

During this part of the transaction, the master becomes the This time, the slave acknowledges the read request, and the master releases the SDAīus but continues supplying the clock to the slave. Register address, the master sends a START condition again, followed by the slave address with the R/W bit set (signifying a write), followed by the register address it wishes to read from. Off the transmission in a similar fashion as the write, by sending the address with the R/W bit equal to 0 The master must first instruct the slave which register it wishes to read from. Reading from a slave is very similar to writing, but requires some additional steps. Is 0x75 correct read address?īased on the device spec for read operation: I don't have any issues writing to this device address and perform the necessary functions, however when I try to read registers using Arduino read functions, getting NACK there. Serial.I am using this TI device TCA9539 ( ) with the pins A1 and A0 tied to ground resulting the write address to 0x74. Size_t actually_read = Wire.readBytes(buf, 4)


Serial.printf("Register value: %08lx\r\n", _builtin_bswap32(buf)) įor an explanation on why we need _builtin_bswap32(), see How to print 32-bit uint32_t as eight hex digits in Arduino Option 2: Reading the register into an uint8_t array const uint8_t SLAVE_I2C_ADDRESS = 0b1010

Size_t actually_read = Wire.readBytes((uint8_t*)&buf, 4) Wire.requestFrom(SLAVE_I2C_ADDRESS, 4) // This register is 32 bits = 4 bytes longĭelay(5) // Wait for data to be available Wire.beginTransmission(SLAVE_I2C_ADDRESS) Option 1: Reading the register into an uint32_t (recommended) const uint8_t SLAVE_I2C_ADDRESS = 0b1010 Ĭonst uint16_t SLAVE_I2C_REGISTER_ADDRESS = 0x50 We will provide a full example with error handling in a followup post. This is a minimal example so it creates minimal confusion for the reader. Additionally, we wait for data using delay() instead of Wire.available(). Note that this code does not implement error handling for the sake of simplicity. In my opinion, it’s most efficient to just try out the standard way of reading a register and start from there. Note that some devices like the LAN9303 have a slightly different addressing scheme or other peculiarities. It will work with almost all I2C devices like EEPROMs, ADCs and others, provided you have the correct. The following code demonstrates how to read a register that is 4 bytes (32 bits) long over I2C.
