File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
APIs_Drivers/UnbufferedSerial Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " mbed.h"
2
+
3
+
4
+ // Create a DigitalOutput object to blink an LED whenever data is received
5
+ static DigitalOut led_serial_read (LED1);
6
+
7
+ // Create a new UnbufferedSerial object with a default baud rate.
8
+ static UnbufferedSerial serial_port (USBTX, USBRX);
9
+
10
+ void on_rxd_interrupt ()
11
+ {
12
+ char c;
13
+
14
+ // Toggle an LED.
15
+ led_serial_read = !led_serial_read;
16
+
17
+ // Read the data to clear the receive interrupt.
18
+ if (serial_port.read (&c, 1 )) {
19
+ // Echo the input back to the terminal.
20
+ serial_port.write (&c, 1 );
21
+ }
22
+ }
23
+
24
+ int main (void ) {
25
+ // Set desired properties (9600-8-N-1).
26
+ serial_port.baud (9600 );
27
+ serial_port.format (
28
+ /* bits */ 8 ,
29
+ /* parity */ SerialBase::None,
30
+ /* stop bit */ 1
31
+ );
32
+
33
+ // Register a callback to process a Rx (receive) interrupt.
34
+ serial_port.attach (&on_rxd_interrupt, SerialBase::RxIrq);
35
+ }
You can’t perform that action at this time.
0 commit comments