Subsection 10.4.8 I2C_CR2, Field by Field
One assignment to
I2C_CR2 describes an entire transaction, which is why it is the register the library writes most. The register is drawn in Figure 10.3.25, beside the code that writes it; what follows here is the detail that would not fit there.
SADD is the field that needs care. The manual is exact: in 7-bit addressing mode, “SADD[7:1] must be written with the 7-bit slave address to be sent. The bits SADD[9], SADD[8] and SADD[0] are don’t care.” The address goes in bits 7 down to 1, which is what the <<1 in the library is doing, and bit 0, where the R/W bit will appear on the wire, is ignored here, because the direction comes from RD_WRN instead.
AUTOEND is worth knowing about because of what the other setting is for. With AUTOEND set, the hardware sends a STOP after NBYTES bytes and the bus goes idle. With it clear, the peripheral instead holds SCL LOW and sets a “transfer complete” flag, which lets software start a second transfer without releasing the bus in between, a repeated START. That is how a read from a device register works, and how i2c1_memRead() does it: write the register address, repeated START, then read, with no STOP in the middle where another controller could take the bus.
