Merge pull request #4245 from bobsrac/feature/examples_nrf52840_ieee802154
nrf52840: example ieee 802.15.4 packet send/receive
This commit is contained in:
commit
1d8e4fd970
38
examples/nrf52840/src/bin/ieee802154_receive.rs
Normal file
38
examples/nrf52840/src/bin/ieee802154_receive.rs
Normal file
@ -0,0 +1,38 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::config::{Config, HfclkSource};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::radio::ieee802154::{self, Packet};
|
||||
use embassy_nrf::{peripherals, radio};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
embassy_nrf::bind_interrupts!(struct Irqs {
|
||||
RADIO => radio::InterruptHandler<peripherals::RADIO>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = Config::default();
|
||||
config.hfclk_source = HfclkSource::ExternalXtal;
|
||||
let peripherals = embassy_nrf::init(config);
|
||||
|
||||
// assumes LED on P0_15 with active-high polarity
|
||||
let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard);
|
||||
|
||||
let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs);
|
||||
let mut packet = Packet::new();
|
||||
|
||||
loop {
|
||||
gpo_led.set_low();
|
||||
let rv = radio.receive(&mut packet).await;
|
||||
gpo_led.set_high();
|
||||
match rv {
|
||||
Err(_) => defmt::error!("receive() Err"),
|
||||
Ok(_) => defmt::info!("receive() {:?}", *packet),
|
||||
}
|
||||
Timer::after_millis(100u64).await;
|
||||
}
|
||||
}
|
||||
39
examples/nrf52840/src/bin/ieee802154_send.rs
Normal file
39
examples/nrf52840/src/bin/ieee802154_send.rs
Normal file
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::config::{Config, HfclkSource};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::radio::ieee802154::{self, Packet};
|
||||
use embassy_nrf::{peripherals, radio};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
embassy_nrf::bind_interrupts!(struct Irqs {
|
||||
RADIO => radio::InterruptHandler<peripherals::RADIO>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = Config::default();
|
||||
config.hfclk_source = HfclkSource::ExternalXtal;
|
||||
let peripherals = embassy_nrf::init(config);
|
||||
|
||||
// assumes LED on P0_15 with active-high polarity
|
||||
let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard);
|
||||
|
||||
let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs);
|
||||
let mut packet = Packet::new();
|
||||
|
||||
loop {
|
||||
packet.copy_from_slice(&[0_u8; 16]);
|
||||
gpo_led.set_high();
|
||||
let rv = radio.try_send(&mut packet).await;
|
||||
gpo_led.set_low();
|
||||
match rv {
|
||||
Err(_) => defmt::error!("try_send() Err"),
|
||||
Ok(_) => defmt::info!("try_send() {:?}", *packet),
|
||||
}
|
||||
Timer::after_millis(1000u64).await;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user