aboutsummaryrefslogtreecommitdiff
path: root/examples/rp235x/src/bin/uart_unidir.rs
diff options
context:
space:
mode:
authorCurly <[email protected]>2025-02-23 07:33:58 -0800
committerCurly <[email protected]>2025-02-23 07:33:58 -0800
commit3932835998802fc3abf7cce4f736e072858ebfd1 (patch)
tree5dd714b99bc74a03556c58809237c88691c293bb /examples/rp235x/src/bin/uart_unidir.rs
parentc3c67db93e627a4fafe5e1a1123e5cbb4abafe47 (diff)
rename `rp23` (?) folder to `rp235x`; fix `ci.sh` to use `rp235x` folder
Diffstat (limited to 'examples/rp235x/src/bin/uart_unidir.rs')
-rw-r--r--examples/rp235x/src/bin/uart_unidir.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/rp235x/src/bin/uart_unidir.rs b/examples/rp235x/src/bin/uart_unidir.rs
new file mode 100644
index 000000000..a45f40756
--- /dev/null
+++ b/examples/rp235x/src/bin/uart_unidir.rs
@@ -0,0 +1,50 @@
1//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
2//!
3//! Test TX-only and RX-only on two different UARTs. You need to connect GPIO0 to GPIO5 for
4//! this to work
5//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
6//! with its UART port.
7
8#![no_std]
9#![no_main]
10
11use defmt::*;
12use embassy_executor::Spawner;
13use embassy_rp::bind_interrupts;
14use embassy_rp::peripherals::UART1;
15use embassy_rp::uart::{Async, Config, InterruptHandler, UartRx, UartTx};
16use embassy_time::Timer;
17use {defmt_rtt as _, panic_probe as _};
18
19bind_interrupts!(struct Irqs {
20 UART1_IRQ => InterruptHandler<UART1>;
21});
22
23#[embassy_executor::main]
24async fn main(spawner: Spawner) {
25 let p = embassy_rp::init(Default::default());
26
27 let mut uart_tx = UartTx::new(p.UART0, p.PIN_0, p.DMA_CH0, Config::default());
28 let uart_rx = UartRx::new(p.UART1, p.PIN_5, Irqs, p.DMA_CH1, Config::default());
29
30 unwrap!(spawner.spawn(reader(uart_rx)));
31
32 info!("Writing...");
33 loop {
34 let data = [1u8, 2, 3, 4, 5, 6, 7, 8];
35 info!("TX {:?}", data);
36 uart_tx.write(&data).await.unwrap();
37 Timer::after_secs(1).await;
38 }
39}
40
41#[embassy_executor::task]
42async fn reader(mut rx: UartRx<'static, UART1, Async>) {
43 info!("Reading...");
44 loop {
45 // read a total of 4 transmissions (32 / 8) and then print the result
46 let mut buf = [0; 32];
47 rx.read(&mut buf).await.unwrap();
48 info!("RX {:?}", buf);
49 }
50}