what exactly are you trying to accomplish?
<<quote>>Hello! I'm trying to send a string from one mbed to another using the Serial functions printf and scanf and it doesn´t works. The code I have on the mbed who sends is the next:<</quote>>
the best way to accomplish this is using an interrupt. Basically, if something arrives on the serial port on your receiving mbed, it automatically saves the data someplace where you can process later
<<quote>>But, I don´t understand why it works in this way. Serial pins and USB pins use the same buffer? What is the relationship between them?<</quote>>
They probably have different buffers
for (int i=0; i<long_command; i++) {
while (true) {
if (micro.writeable()) {
result = micro.putc(command[i]);
pc.printf("Putc result: %X\r\n",result);
break;
}
}
}
is this the code on the transmitter?
Hello! I'm trying to send a string from one mbed to another using the Serial functions printf and scanf and it doesn´t works. The code I have on the mbed who sends is the next:
#include "mbed.h" Serial micro(p9, p10);//tx, rx Serial pc(USBTX,USBRX);//tx, rx const char command[9]={0xF2, 0x00, 0x09, 0xff, 0x22, 0x00, 0x05, 0x79, 0x6F}; int err; int main() { micro.format(8, Serial::None, 1); micro.baud(19200); pc.format(8, Serial::None, 1); pc.baud(9600); while (true) { if (micro.writeable()) { err= micro.printf(command); break; } } pc.printf("Printf returns: %d\r\n", err); }And in the mbed who receives:
#include "mbed.h" Serial micro(p9, p10); Serial pc(USBTX,USBRX); int err; char command[9]; int main() { micro.format(8, Serial::None, 1); micro.baud(19200); pc.format(8, Serial::None, 1); pc.baud(9600); while (true) { if (micro.readable()) { err= micro.scanf(command); break; } } pc.printf("Command Received: \r\n"); for (int i=0;i<sizeof(command);i++){ pc.printf("%X",command[i]); } pc.printf("\r\n"); pc.printf("Scanf returns: %d\r\n",err); }After executing the scanf works but it receives all 0 and returns a 0 too. I use the USBTX and USBRX to see in the Terminal what is happening. I tried too using "%s" before the string (micro.scanf("%s", command)) but in this way, I don´t receive anything. The scanf doesn´t work. I also realized that the printf and the scanf returns an integer, but I have no idea what it means (I didn't find information anywhere)
Does anybody what is wrong in my code?
Thank you so much!!!!
María.