Crossed Wires

I2C Sensor Fields Read Wrong Debug

Symptom

The terminal shows ID:0x5A, which is right, then TEMP:265, STATUS:0xF5 and PRESS:65535. The registers and bit fields are on the Datasheet tab.

Circuit

Bench wiring: U2, an environmental sensor at I2C address 0x48, connects to U1, an STM32F4, on SCL to PB6 and SDA to PB7, each line pulled up to 3.3 volts; U1's USART1 transmit line on PA9 runs to a serial console
U2's register block: 0x00 device ID, 0x01 and 0x02 temperature low then high byte in hundredths of a degree, 0x03 status, 0x04 and 0x05 pressure low then high byte in hectopascals; registers from 0x06 up read as 0xFF

Pass condition

Once after reset, USART1 prints four lines from one read of U2's block: ID and STATUS in hex, TEMP and PRESS in decimal.

Expected output for the first read: U2 sends 5A 29 09 01 F5 03 from register 0x00, and the console prints ID:0x5A, TEMP:2345, STATUS:0x01 and PRESS:1013

Notes

The bench's U2 steps its register pointer per byte, so one read from 0x00 returns the block. Only I2C1 needs its clock enabled on this bench, and the program does that.

Related challenges

Loading the interactive arena.