Skip to main content

Subsection 12.2.2 Part 2: Wire It and Verify the Link

We’ll wire the sensor to the bus with four leads, and then run a short test program to check that the STM32C031C6 can talk to it.
Figure 12.2.2. The LSM303AGR breakout and its STEMMA QT cable. Either socket on the breakout takes the cable’s plug, and it only fits one way. Its four wires go to the Nucleo: black to GND, red to 3.3 V, yellow to SCL (D15, PB8), and blue to SDA (D14, PB9), the same SCL and SDA rows the display is already using. The pin the red wire feeds is VIN; the board accepts either 3.3 or 5 V logic, and in this course we use 3.3 V.
Figure 12.2.4. The accelerometer joins the bus: yellow to the SCL row, blue to the SDA row, black to GND, and red to 3.3 V. The display, not drawn here, stays wired to the same two rows.

Activity 12.2.2. Wire the accelerometer and verify the link.

The program we’ll run, whoami_test.c, reads a certain register, called WHO_AM_I, once a second and prints whether it got the value it expected.

(a)

Plug the STEMMA QT cable into the breakout and wire its four leads: black to GND, red to 3.3 V, yellow to SCL (D15, PB8), and blue to SDA (D14, PB9), as in Figure 12.2.2.

(b)

Make a copy of your TemplateProject and call the new project Accelerometer. Download whoami_test.c from the book’s starter files and put it in the project’s Src folder. Build and upload.

(c)

Open CoolTerm. The program should print Accelerometer initialized! once a second.