From 2ef4a45fa0e153cb6435c4dc52f19108ca808cc7 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 18 Oct 2021 15:24:31 +0200 Subject: Add support for temperature sensor peripheral * Add TEMP peripheral to all nRF52 chips * Add async HAL for reading temperature values * Add example application reading temperature values --- examples/nrf/src/bin/temp.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/nrf/src/bin/temp.rs (limited to 'examples') diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs new file mode 100644 index 000000000..04d1d58fe --- /dev/null +++ b/examples/nrf/src/bin/temp.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::*; + +use defmt::panic; +use embassy::{ + executor::Spawner, + time::{Duration, Timer}, +}; +use embassy_nrf::{interrupt, temp::Temp, Peripherals}; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let irq = interrupt::take!(TEMP); + let mut temp = Temp::new(p.TEMP, irq); + + loop { + let value = temp.read().await; + info!("temperature: {}", value.to_num::()); + Timer::after(Duration::from_secs(1)).await; + } +} -- cgit