Skip to content

Commit f18eb2c

Browse files
committed
Mirrored from master snippet repository
0 parents  commit f18eb2c

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#UnbufferedSerial
2+
3+
MIRRORED FROM MASTER EXAMPLE SNIPPETS REPOSITORY: mbed-os-examples-docs_only.
4+
ANY CHANGES MADE DIRECTLY TO THIS REPOSITORY WILL BE AUTOMATICALLY OVERWRITTEN.

main.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
// Create a DigitalOutput object to toggle an LED whenever data is received.
9+
static DigitalOut led(LED1);
10+
11+
// Create a UnbufferedSerial object with a default baud rate.
12+
static UnbufferedSerial serial_port(USBTX, USBRX);
13+
14+
void on_rx_interrupt()
15+
{
16+
char c;
17+
18+
// Toggle the LED.
19+
led = !led;
20+
21+
// Read the data to clear the receive interrupt.
22+
if (serial_port.read(&c, 1)) {
23+
// Echo the input back to the terminal.
24+
serial_port.write(&c, 1);
25+
}
26+
}
27+
28+
int main(void)
29+
{
30+
// Set desired properties (9600-8-N-1).
31+
serial_port.baud(9600);
32+
serial_port.format(
33+
/* bits */ 8,
34+
/* parity */ SerialBase::None,
35+
/* stop bit */ 1
36+
);
37+
38+
// Register a callback to process a Rx (receive) interrupt.
39+
serial_port.attach(&on_rx_interrupt, SerialBase::RxIrq);
40+
}

mbed-os.lib

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#9a8c9e2c297f64c805698d72cd541ff3cd7fe538

0 commit comments

Comments
 (0)