Skip to main content

Subsection 12.2.5 Part 5: Digging Deeper

You now have a decoded trace on your screen. We’ll work through the questions it raises, and we can answer every one of them from the trace itself.

Activity 12.2.5. Why 0x19?

The program writes the device address as (0x32 >> 1). Where does the 0x32 come from, and why does the decoder print h19?

Activity 12.2.6. Digging deeper, against your own trace.

Answer these from your own decoded trace.

(a)

We saw earlier that our i2c1_memRead() sends the register address and then starts the read with a repeated START instead of a STOP. Confirm it on the trace in front of you: find where the first transaction ends and the second begins, and what the device address is doing there a second time.

(b)

Find every acknowledge bit on the trace in front of you. There is one after each byte. For each one: who sent it, and is it an ACK or a NACK?
Two different things on this bus are both called a NACK, a not-acknowledge. The NACK on your trace is the controller’s, and it is part of a successful read: the controller asked for one byte, got it, and deliberately does not acknowledge, which tells the target to stop sending. The other kind is the one we saw and produced with the display: nothing pulls SDA LOW during the acknowledge bit, and the wire simply stays HIGH.
The transfer diagram in Figure 10.4.4 is the LSM303AGR datasheet’s own drawing of what you captured: §6.1.1, Tables 20–23, and Table 22 is the shape your trace has. Three more questions can be answered from its rows: who sends the address, where we tell the accelerometer which register to read from, and where the accelerometer puts the register’s contents on the data line. The repeated START between the two halves of the read on your trace is the SR on the datasheet’s drawing; the register-level walk of i2c1_memRead() in Subsection 10.4.9 shows exactly where our library produces it, and why it matters on a bus with two controllers. The NACK you found on your own trace is in neither half of that listing: the library describes the whole transaction in advance, how many bytes (NBYTES) and what to do at the end (AUTOEND). The I2C hardware puts the acknowledge bits and the STOP on the wire.