transmit what you receive in both directions
Pass serial data to/from a one uart to another. Useful for accessing the serial interface from a connected module such as WiFi or Cellular.
Revision 12:c922ba772e30, committed 2019-09-13
- Comitter:
- maclobdell
- Date:
- Fri Sep 13 15:37:35 2019 +0000
- Parent:
- 11:0fa38cb22ea9
- Commit message:
- update to RawSerial to allow send/receive form interrupt context; update Mbed OS version to latest
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Sep 02 15:15:05 2016 +0100 +++ b/main.cpp Fri Sep 13 15:37:35 2019 +0000 @@ -1,13 +1,50 @@ #include "mbed.h" +void recieve_this(void); +void recieve_that(void); + DigitalOut led1(LED1); +DigitalOut led2(LED2); +RawSerial this_way(USBTX,USBRX); +RawSerial that_way(D1,D0); + // main() runs in its own thread in the OS // (note the calls to Thread::wait below for delays) int main() { + + + this_way.baud(115200); + /** attach the callback function to be called whenever a character is received */ + this_way.attach(&recieve_this, Serial::RxIrq); + ///set the baud rate + that_way.baud(115200); + /** attach the callback function to be called whenever a character is received */ + that_way.attach(&recieve_that, Serial::RxIrq); + + while (true) { - led1 = !led1; - Thread::wait(500); + Thread::wait(1000); } } + +void recieve_this(void) +{ + ///blink an led for fun + led1 = !led1; + /** get a character, then put it back on the other interface */ + that_way.putc(this_way.getc()); + +} +/** get incoming data from second serial interface and put to other + * @param none + * @returns none + */ +void recieve_that(void) +{ + ///blink an led for fun + led2 = !led2; + /** get a character, then put it back on the other interface */ + this_way.putc(that_way.getc()); +} \ No newline at end of file
--- a/mbed-os.lib Fri Sep 02 15:15:05 2016 +0100 +++ b/mbed-os.lib Fri Sep 13 15:37:35 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#bdab10dc0f90748b6989c8b577771bb403ca6bd8 +https://github.com/ARMmbed/mbed-os/#1bf6b20df9d3cd5f29f001ffc6f0d0fcbbb96118