embassy/examples/nrf52840/src/bin/uart_idle.rs

40 lines
1.0 KiB
Rust
Raw Permalink Normal View History

2021-05-10 23:04:37 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
use embassy_nrf::peripherals::UARTE0;
use embassy_nrf::{bind_interrupts, uarte};
2022-06-12 22:15:44 +02:00
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
UARTE0_UART0 => uarte::InterruptHandler<UARTE0>;
});
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_nrf::init(Default::default());
2021-05-10 23:04:37 +02:00
let mut config = uarte::Config::default();
config.parity = uarte::Parity::EXCLUDED;
config.baudrate = uarte::Baudrate::BAUD115200;
let uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config);
let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1);
2021-05-10 23:04:37 +02:00
info!("uarte initialized!");
// Message must be in SRAM
let mut buf = [0; 8];
buf.copy_from_slice(b"Hello!\r\n");
unwrap!(tx.write(&buf).await);
2021-05-10 23:04:37 +02:00
info!("wrote hello in uart!");
loop {
info!("reading...");
let n = unwrap!(rx.read_until_idle(&mut buf).await);
2021-05-10 23:04:37 +02:00
info!("got {} bytes", n);
}
}