Postcard

STM32 SPI Register Read Exercise

Task

The bench plays the sensor on SPI1. Bring up SPI1. Once after reset, write 0x42 to the sensor's register 0x20, then read register 0x28 and print the value. The registers and bit fields are on the Datasheet tab.

Circuit

Block diagram: U1 STM32F4 wired to U2, an SPI sensor: PA4 to CS with R1 pulling it up to +3V3, PA5 to SCK, PA6 from SDO, PA7 to SDI, and PA9 carrying the USART1 report to TP1, a serial monitor

Pass condition

The logic analyzer must show the write and then the read, each in its own CS frame. The terminal must print READ:0x and the value in two hex digits.

Expected output: chip select goes low twice, first for the write and then for the read, and the terminal prints READ:0x followed by the value register 0x28 holds

Notes

The sensor uses SPI mode 0. Frames start with the register byte, bit 7 set to read. Send 0x00 where a byte has no data. USART1, uart_puts and uart_put_hex are given.

Related challenges

Loading the interactive arena.