Lifeboat

A thermal management system monitors a heater using an I2C temperature sensor (address 0x48) on I2C1. An actuator (heater relay) is connected to PA5, active-high.

The sensor has two temperature registers:

  • Register 0x00: live measurement (updated in real-time)
  • Register 0x01: backup value (factory-calibrated reference)

During normal operation, the firmware reads the live register (0x00) and keeps the actuator enabled. If the live register returns fault values (0xFF, meaning the ADC is saturated), the firmware should fall back to the backup register (0x01). If both registers return 0xFF, the firmware must enter a safe state: disable the actuator (drive PA5 low) and report the failure.

The firmware should attempt each register up to 3 times before declaring it failed. A reading of 0xFF indicates a fault.

The values each register reports are chosen fresh for every submission, so the only way to answer correctly is to actually read the sensor over I2C and apply the failover logic to whatever it returns. A memorized reply will not match the reading this run produces.

Expected UART output: Live reading OK: "LIVE:<temp>" Backup reading OK: "BACKUP:<temp>" Both failed: "STATUS:SAFE"

Print the temperature each register reports as a decimal: the live reading as "LIVE:<temp>", or the backup as "BACKUP:<temp>" when live fails, or "STATUS:SAFE" when both fail.

Each output line must end with a newline character (\n); output is matched exactly.

The starter code has register definitions, UART and I2C helpers, and GPIO setup scaffolding. Implement the sensor polling, failover logic, and safe-state shutdown.

Loading the interactive arena.