Subsection 12.1.3 The WHO_AM_I Register
Whereas the HT16K33 on the display’s backpack took one-byte commands (Chapter 10), the accelerometer is operated entirely through its internal registers: each register has an address inside the device, we configure the sensor by writing to some of them, and we get measurements out by reading others. Which registers exist, and what each bit in them means, comes from the device’s datasheet: for this chapter, the LSM303AGR datasheet.
One of those registers exists purely so that you can check the connection: the accelerometer’s WHO_AM_I register always contains the value 0x33. It is read-only, and its contents are fixed when the chip is manufactured (Datasheet §8.4, register WHO_AM_I_A, address 0x0F: the default value 00110011 is 0x33). If you read the WHO_AM_I register and get the right result, you can be confident in your I2C setup: the wiring, the device address, and your whole read path all had to work for that 0x33 to arrive.
Many I2C sensors have a register like this, because a value that is known in advance gives you something to check against before you rely on any of the sensor’s measurements. Device drivers use it the same way: a driver’s initialization function typically reads WHO_AM_I first, and reports failure if the expected value does not come back. In class we’ll run a short test program that does exactly this check once your sensor is wired up.
