Vital Signs
A field-deployed environmental monitoring unit runs FreeRTOS and needs a monitoring task that reads two sensors, validates the data, feeds a watchdog, and enters safe mode if a sensor goes offline.
The hardware:
- I2C temperature sensor on I2C1, slave address 0x48, register 0x00
returns 1 byte (degrees Celsius)
- SPI pressure sensor on SPI1, returns 2 bytes per transfer
(big-endian, in hectopascals)
- Independent Watchdog (IWDG) configured for ~1s timeout
(prescaler /32, reload 1000)
Create a FreeRTOS task that runs 3 monitoring cycles. Each cycle:
- Read the temperature sensor via I2C
- If the reading is 0xFF (fault), immediately enter safe mode
- Read the pressure sensor via SPI (2 bytes, big-endian)
- Print "TEMP:<celsius>" and "PRES:<hectopascals>"
- Feed the watchdog and print "WDG:OK"
After 3 healthy cycles, print "STATUS:OK". If a fault is detected, print "STATUS:SAFE" and stop.
For example, if the temperature sensor returns 24 and the pressure sensor returns bytes 0x03 0xE8 (1000 hPa), each healthy cycle prints: TEMP:24 PRES:1000 WDG:OK and the run ends with STATUS:OK on its own line after the third cycle.
Each output line must end with a newline character (\n); UART output is matched exactly.
The starter code provides register definitions and working UART helpers. Implement the monitor task with peripheral init, sensor reads, watchdog setup, monitoring loop, and safe-mode logic.