Skip to main content

Subsection 12.2.1 Part 1: Back to I2C, a Second Device on the Bus

The LSM303AGR accelerometer is an I2C device. All I2C devices use the same two-wire bus (the same as we used with the display), with SDA and SCL held HIGH by pull-up resistors. The accelerometer speaks the same protocol as the display, so we can use the same I2C library: the five I2C functions we used with the display are all we need to talk to it. It also has a magnetometer, but weโ€™ll only use the accelerometer in this class.

Activity 12.2.1. Do I have to take the display down?

Suppose your seven-segment display is still connected to the I2C pins of your Nucleo, and today we are adding the accelerometer, a second I2C device. Do you need to take the display down first? What if you wanted to use both the accelerometer and the display in one project? Commit to an answer, and to a reason, before we discuss it.
No, the display stays: both devices share the same two wires, and each has its own address. Every transaction opens with the address of the device the controller wants to communicate with, so the display simply does not respond to transactions addressed to the accelerometer, and the other way around. Letting several devices share two wires is the reason the bus exists, and in Lab 7 you will run both devices on one bus, so leave the display wired.