Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 1 month ago.
How to use the "write" function in Serial library
I just need to find some examples to use de "write" or "read" functions in serial library, the objetive is to transmit data from RF modules, thats why i need to use the serial communication with the extern pins. Thanks for help.
1 Answer
8 years ago.
To write to the serial port, use putc or printf:
Serial other_device(D1, D0); other_device.putc(0x12); // sends a character
To read you have multiple options. One is to wait until there is data on the link and then receive this data, you can do this in a separate thread to not block your other code:
while (other_device.readable()) {
char c = other_device.getc();
}
Or, you can read by attaching an interrupt on the serial bus, which will fire whenever there is data through the attach function.