diff options
| author | Curly <[email protected]> | 2025-02-23 07:33:58 -0800 |
|---|---|---|
| committer | Curly <[email protected]> | 2025-02-23 07:33:58 -0800 |
| commit | 3932835998802fc3abf7cce4f736e072858ebfd1 (patch) | |
| tree | 5dd714b99bc74a03556c58809237c88691c293bb /examples/rp235x/src/bin/uart_unidir.rs | |
| parent | c3c67db93e627a4fafe5e1a1123e5cbb4abafe47 (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.rs | 50 |
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 | |||
| 11 | use defmt::*; | ||
| 12 | use embassy_executor::Spawner; | ||
| 13 | use embassy_rp::bind_interrupts; | ||
| 14 | use embassy_rp::peripherals::UART1; | ||
| 15 | use embassy_rp::uart::{Async, Config, InterruptHandler, UartRx, UartTx}; | ||
| 16 | use embassy_time::Timer; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 18 | |||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | UART1_IRQ => InterruptHandler<UART1>; | ||
| 21 | }); | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async 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] | ||
| 42 | async 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 | } | ||
