Skip to main content

Subsection 10.4.11 The Register Read/Write Pattern

The HT16K33 is unusual in being almost stateless: you send it a command or a block of display data and it acts. Most I2C parts are organized as a set of numbered registers instead, and their datasheets describe access to those registers in the four shapes of Figure 10.4.4. It is worth reading now, because it is the pattern behind i2c1_memWrite() and i2c1_memRead(), and because every I2C sensor you meet later is documented this way.
Figure 10.4.4. The four register-access transfers, as the LSM303AGR’s datasheet draws them (§6.1.1), the accelerometer you meet in Chapter 12, with the sequence written out underneath the two single-byte cases. ST is the START and SP the STOP; SAD is the device address; SUB is the sub-address, meaning the register number inside the device; SAK is the target’s acknowledge; SR is a repeated START; and MAK and NMAK are the controller’s own acknowledge and final not-acknowledge when it is the one receiving. A write is device address, register number, then data bytes, and the register number advances by itself for each further byte, which is exactly what the HT16K33’s display data pointer does. A read needs both directions, in two transactions joined by a repeated START. The write carries the device address and the register number. The repeated START follows with no STOP before it, so the bus is never released, and the read carries the device address again with the read bit while the data comes back.
The repeated START in the read case is the reason AUTOEND exists as a choice rather than always being on. A STOP between the two halves would free the bus, and on a bus with a second controller on it the register pointer you just set could be changed by somebody else before you read from it.