diff options
| author | Ulf Lilleengen <[email protected]> | 2025-05-27 07:11:34 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-27 07:11:34 +0000 |
| commit | 1d8e4fd970ea1794e5a726781442f13c2b2c2b66 (patch) | |
| tree | da412ca4ecf50f11f7703e9783c2ca2562a7f132 /examples | |
| parent | 5f3204f9c341f48b53b81c443f3c2535a6c855da (diff) | |
| parent | f761e4b97b533388433ac3de8063d0a1aa2dc0e0 (diff) | |
Merge pull request #4245 from bobsrac/feature/examples_nrf52840_ieee802154
nrf52840: example ieee 802.15.4 packet send/receive
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf52840/src/bin/ieee802154_receive.rs | 38 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/ieee802154_send.rs | 39 |
2 files changed, 77 insertions, 0 deletions
diff --git a/examples/nrf52840/src/bin/ieee802154_receive.rs b/examples/nrf52840/src/bin/ieee802154_receive.rs new file mode 100644 index 000000000..ede8fca65 --- /dev/null +++ b/examples/nrf52840/src/bin/ieee802154_receive.rs | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_nrf::config::{Config, HfclkSource}; | ||
| 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 7 | use embassy_nrf::radio::ieee802154::{self, Packet}; | ||
| 8 | use embassy_nrf::{peripherals, radio}; | ||
| 9 | use embassy_time::Timer; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | embassy_nrf::bind_interrupts!(struct Irqs { | ||
| 13 | RADIO => radio::InterruptHandler<peripherals::RADIO>; | ||
| 14 | }); | ||
| 15 | |||
| 16 | #[embassy_executor::main] | ||
| 17 | async fn main(_spawner: Spawner) { | ||
| 18 | let mut config = Config::default(); | ||
| 19 | config.hfclk_source = HfclkSource::ExternalXtal; | ||
| 20 | let peripherals = embassy_nrf::init(config); | ||
| 21 | |||
| 22 | // assumes LED on P0_15 with active-high polarity | ||
| 23 | let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard); | ||
| 24 | |||
| 25 | let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs); | ||
| 26 | let mut packet = Packet::new(); | ||
| 27 | |||
| 28 | loop { | ||
| 29 | gpo_led.set_low(); | ||
| 30 | let rv = radio.receive(&mut packet).await; | ||
| 31 | gpo_led.set_high(); | ||
| 32 | match rv { | ||
| 33 | Err(_) => defmt::error!("receive() Err"), | ||
| 34 | Ok(_) => defmt::info!("receive() {:?}", *packet), | ||
| 35 | } | ||
| 36 | Timer::after_millis(100u64).await; | ||
| 37 | } | ||
| 38 | } | ||
diff --git a/examples/nrf52840/src/bin/ieee802154_send.rs b/examples/nrf52840/src/bin/ieee802154_send.rs new file mode 100644 index 000000000..7af9d1d06 --- /dev/null +++ b/examples/nrf52840/src/bin/ieee802154_send.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_nrf::config::{Config, HfclkSource}; | ||
| 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 7 | use embassy_nrf::radio::ieee802154::{self, Packet}; | ||
| 8 | use embassy_nrf::{peripherals, radio}; | ||
| 9 | use embassy_time::Timer; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | embassy_nrf::bind_interrupts!(struct Irqs { | ||
| 13 | RADIO => radio::InterruptHandler<peripherals::RADIO>; | ||
| 14 | }); | ||
| 15 | |||
| 16 | #[embassy_executor::main] | ||
| 17 | async fn main(_spawner: Spawner) { | ||
| 18 | let mut config = Config::default(); | ||
| 19 | config.hfclk_source = HfclkSource::ExternalXtal; | ||
| 20 | let peripherals = embassy_nrf::init(config); | ||
| 21 | |||
| 22 | // assumes LED on P0_15 with active-high polarity | ||
| 23 | let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard); | ||
| 24 | |||
| 25 | let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs); | ||
| 26 | let mut packet = Packet::new(); | ||
| 27 | |||
| 28 | loop { | ||
| 29 | packet.copy_from_slice(&[0_u8; 16]); | ||
| 30 | gpo_led.set_high(); | ||
| 31 | let rv = radio.try_send(&mut packet).await; | ||
| 32 | gpo_led.set_low(); | ||
| 33 | match rv { | ||
| 34 | Err(_) => defmt::error!("try_send() Err"), | ||
| 35 | Ok(_) => defmt::info!("try_send() {:?}", *packet), | ||
| 36 | } | ||
| 37 | Timer::after_millis(1000u64).await; | ||
| 38 | } | ||
| 39 | } | ||
