diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-10 23:04:37 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-05-10 23:06:32 +0200 |
| commit | 95439b493f4325c38e62e669fec81bb4892f3dcd (patch) | |
| tree | 40d2d7ab6828477c54c5fa97ab91541ea754cf10 /embassy-nrf-examples/src | |
| parent | 0a3c2365107999b785eb74c9a7d2ff4da2377bb9 (diff) | |
Add uart_idle example.
Diffstat (limited to 'embassy-nrf-examples/src')
| -rw-r--r-- | embassy-nrf-examples/src/bin/uart_idle.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/embassy-nrf-examples/src/bin/uart_idle.rs b/embassy-nrf-examples/src/bin/uart_idle.rs new file mode 100644 index 000000000..54d524ae5 --- /dev/null +++ b/embassy-nrf-examples/src/bin/uart_idle.rs | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(min_type_alias_impl_trait)] | ||
| 4 | #![feature(impl_trait_in_bindings)] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | #![allow(incomplete_features)] | ||
| 7 | |||
| 8 | #[path = "../example_common.rs"] | ||
| 9 | mod example_common; | ||
| 10 | use embassy_traits::uart::ReadUntilIdle; | ||
| 11 | use example_common::*; | ||
| 12 | |||
| 13 | use defmt::panic; | ||
| 14 | use embassy::executor::Spawner; | ||
| 15 | use embassy::traits::uart::{Read, Write}; | ||
| 16 | use embassy::util::Steal; | ||
| 17 | use embassy_nrf::gpio::NoPin; | ||
| 18 | use embassy_nrf::{interrupt, uarte, Peripherals}; | ||
| 19 | |||
| 20 | #[embassy::main] | ||
| 21 | async fn main(spawner: Spawner) { | ||
| 22 | let p = unsafe { Peripherals::steal() }; | ||
| 23 | |||
| 24 | let mut config = uarte::Config::default(); | ||
| 25 | config.parity = uarte::Parity::EXCLUDED; | ||
| 26 | config.baudrate = uarte::Baudrate::BAUD115200; | ||
| 27 | |||
| 28 | let irq = interrupt::take!(UARTE0_UART0); | ||
| 29 | let mut uart = unsafe { | ||
| 30 | uarte::UarteWithIdle::new( | ||
| 31 | p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, NoPin, NoPin, config, | ||
| 32 | ) | ||
| 33 | }; | ||
| 34 | |||
| 35 | info!("uarte initialized!"); | ||
| 36 | |||
| 37 | // Message must be in SRAM | ||
| 38 | let mut buf = [0; 8]; | ||
| 39 | buf.copy_from_slice(b"Hello!\r\n"); | ||
| 40 | |||
| 41 | unwrap!(uart.write(&buf).await); | ||
| 42 | info!("wrote hello in uart!"); | ||
| 43 | |||
| 44 | loop { | ||
| 45 | info!("reading..."); | ||
| 46 | let n = unwrap!(uart.read_until_idle(&mut buf).await); | ||
| 47 | info!("got {} bytes", n); | ||
| 48 | } | ||
| 49 | } | ||
