Scroll

I2C Multi Byte Read Exercise

Task

Once after reset, read the bench accelerometer's X, Y and Z in one transaction and print them. The registers and bit fields are on the Datasheet tab.

The accelerometer's output registers: 0x28 and 0x29 are X low and high, 0x2A and 0x2B Y, 0x2C and 0x2D Z; each axis is a signed 16-bit value, low byte first; with bit 7 of the register address set, the address advances after every byte read

Circuit

Block diagram: U1, an STM32F4, drives SCL on PB6 and SDA on PB7 to U2, a 3-axis accelerometer at address 0x48, with pull-ups R1 and R2 to 3V3 and TP1, a logic analyzer, on both lines; PA9 carries USART1 TX to J1, a serial console

Pass condition

TP1 shows one transaction that writes the register address, then reads exactly six bytes. USART1 prints three axes in decimal, on one line.

Expected output with the board lying flat: on the sensor bus one transaction, a write of A8 to 0x48 then a read of six bytes E8 03 06 FF 80 40 from it; then the line X:1000 Y:-250 Z:16512 on the serial console

Notes

The given code brings up USART1 and I2C1, clock included. uart_puts and uart_puti print.

Related challenges

Loading the interactive arena.