Skip to main content

Check Your Understanding 12.1.4 Check Your Understanding

1.

The I2C bus has only two wires, shared by every device on it. When the controller starts a transaction, how does the right device know the transaction is meant for it?
  • Every transaction begins with a device address, seven address bits plus a read/write bit. All the targets hear it, and only the device that recognizes the address as its own acknowledges and takes part.
  • Correct. Addressing is what lets many devices share the same two wires, since each target answers only to its own address.
  • Each device is wired to the controller through its own pair of SDA and SCL lines.
  • Separate wires per device is exactly what I2C avoids. That was UART’s limitation. All I2C devices share one SDA and one SCL, and the address at the start of each transaction says who is being spoken to.
  • The devices take turns in a fixed order, one transaction each.
  • There is no rotation schedule on the bus. The controller decides whom to address, whenever it wants, by sending that device’s address first.
  • The controller raises SCL to a higher voltage for the device it wants.
  • SCL is the shared clock, and it only ever switches between LOW and 3.3 V. Selection happens with data (the 7-bit address sent at the start of every transaction), not with voltage levels.

2.

To read the accelerometer’s WHO_AM_I register, the program must tell the sensor which register it wants and then collect the byte stored there. Which I2C library function does that whole job?
  • i2c1_memRead(): it takes the device address and a register address, and reads one or more bytes from that location inside the target.
  • Correct. Reading a specific register is a two-step conversation (say which register, then read), and i2c1_memRead() carries out both steps.
  • i2c1_byteRead(): it reads one byte from a target device.
  • i2c1_byteRead() takes only a device address, no register address, so there is no way to tell the sensor which of its many registers you mean. Reading a specific register needs i2c1_memRead(), which takes the register address too.
  • i2c1_memWrite(): it sends the register address to the device.
  • i2c1_memWrite() does send a register address, but what follows is data written into the device. To get the register’s contents back out, the function is i2c1_memRead().
  • i2c1_init(): it sets up the bus, which includes scanning the registers.
  • i2c1_init() configures the STM32C031C6’s own I2C peripheral and pins. It sends nothing to any target device, and it does not read registers.

3.

Your program reads the accelerometer’s WHO_AM_I register and gets 0x33, the expected value. What does that tell you?
  • The I2C link works end to end: the wiring, the device address, and the read path all functioned, because the expected value arrived over them.
  • Correct. WHO_AM_I’s value is fixed in advance, which is exactly what makes it useful for this check.
  • The accelerometer is configured and its measurements are ready to use.
  • WHO_AM_I says nothing about configuration, since its value is fixed at manufacture and never changes. Setting the sensor’s mode and range is separate work, done through other registers.
  • The sensor’s I2C address is 0x33.
  • 0x33 is the contents of the WHO_AM_I register, not the device’s bus address. To read the register at all, the program already had to know the device’s address and use it.
  • The sensor passed its power-on self-test of the measurement hardware.
  • Reading WHO_AM_I exercises none of the measurement hardware, since the register is a fixed constant. What the successful read demonstrates is that the bus and your read path work.