aboutsummaryrefslogtreecommitdiff
path: root/examples/lpc55s69/src/bin/usart_blocking.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lpc55s69/src/bin/usart_blocking.rs')
-rw-r--r--examples/lpc55s69/src/bin/usart_blocking.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/lpc55s69/src/bin/usart_blocking.rs b/examples/lpc55s69/src/bin/usart_blocking.rs
new file mode 100644
index 000000000..a38ec0c5b
--- /dev/null
+++ b/examples/lpc55s69/src/bin/usart_blocking.rs
@@ -0,0 +1,40 @@
1#![no_std]
2#![no_main]
3
4use core::str::from_utf8_mut;
5
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_nxp::usart::{Config, Usart};
9use embassy_time::Timer;
10use {defmt_rtt as _, panic_halt as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_nxp::init(Default::default());
15 let mut usart = Usart::new_blocking(p.USART2, p.PIO0_27, p.PIO1_24, Config::default());
16 let tx_buf = b"Hello, Ferris!";
17 let mut rx_buf = [0u8; 14];
18
19 loop {
20 info!("Write a message");
21 usart.blocking_write(tx_buf).unwrap();
22 usart.blocking_flush().unwrap();
23
24 Timer::after_millis(500).await;
25
26 info!("Read a message");
27 usart.blocking_read(&mut rx_buf).unwrap();
28
29 match from_utf8_mut(&mut rx_buf) {
30 Ok(str) => {
31 info!("The message is: {}", str);
32 }
33 Err(_) => {
34 error!("Error in converting to UTF8");
35 }
36 }
37
38 Timer::after_millis(500).await;
39 }
40}