Expand description
Temperature monitor.
IMPORTANT NOTE:
On 10xx MCUs, the temperature sensor uses and assumes that the bandgap reference, 480MHz PLL and 32KHz RTC modules are properly programmed and fully settled for correct operation.
Example 1
Manually triggered read
use imxrt_hal as hal;
use imxrt_ral as ral;
let inst = unsafe { ral::tempmon::TEMPMON::instance() };
let mut temp_mon = hal::tempmon::TempMon::new(inst);
loop {
if let Ok(temperature) = nb::block!(temp_mon.measure_temp()) {
// Temperature in mC (1°C = 1000°mC)
}
}
Example 2
Non-blocking reading
use imxrt_hal::tempmon::TempMon;
use imxrt_ral as ral;
let inst = unsafe { ral::tempmon::TEMPMON::instance() };
// Init temperature monitor with 8Hz measure freq
// 0xffff = 2 Sec. Read more at `measure_freq()`
let mut temp_mon = TempMon::with_measure_freq(inst, 0x1000);
temp_mon.start();
let mut last_temp = 0_i32;
loop {
// Get the last temperature read by the measure_freq
if let Ok(temp) = temp_mon.get_temp() {
if last_temp != temp {
// Temperature changed
last_temp = temp;
}
// Do something else
}
}
Example 3
Low and high temperature Interrupt
NOTE: TEMP_LOW_HIGH is triggered for TempSensor low
and TempSensor high
use imxrt_hal::tempmon::TempMon;
use imxrt_ral as ral;
let inst = unsafe { ral::tempmon::TEMPMON::instance() };
// Init temperature monitor with 8Hz measure freq
// 0xffff = 2 Sec. Read more at `measure_freq()`
let mut temp_mon = TempMon::with_measure_freq(inst, 0x1000);
// Set low_alarm, high_alarm, and panic_alarm temperature
temp_mon.set_alarm_values(-5_000, 65_000, 95_000);
// Use values from registers if you like to compare it somewhere
let (low_alarm, high_alarm, panic_alarm) = temp_mon.alarm_values();
// Enables interrupts for low_high_alarm
unsafe {
cortex_m::peripheral::NVIC::unmask(ral::interrupt::TEMP_LOW_HIGH);
}
// Start could fail if the module is not powered up
if temp_mon.start().is_err() {
temp_mon.power_up();
temp_mon.start();
}
// #[cortex_m_rt::interrupt]
fn TEMP_LOW_HIGH() {
// disable the interrupt to avoid endless triggers
cortex_m::peripheral::NVIC::mask(ral::interrupt::TEMP_LOW_HIGH);
// don't forget to enable it after the temperature is back to normal
}
Structs
- Indicates that the temperature monitor is powered down.
- A Temperature Monitor (TEMPMON)