9 years ago.

16-bit addressing in I2C

Hi all,

I would like to use the I2C bus in order to have two mcu's talk to each other. Because the slave I2C has more than 256 registers I was wondering how is it possible to have 2 bytes for addressing.

From what I saw the I2C.write is only for 8 bit -addresses. Is it possible to do sth with mbed or I will have to code it from scratch? Also if I go down that route how should I do it.

Thanks for your time.

1 Answer

9 years ago.

The regular I2C slave device address is always 8 bit (actually 7 bit since the LSB is used to indicate read or write operations). The I2C standard does have a mode with extended address range of 10 bits. In this case the first address byte must be 11110 A9 A8 R/W followed by a second slave address byte for the remaining bits. This mode is not used very often. However, you seem to be looking for a way to address a single slave that has a larger internal addressing range (ie registers). This is possible by either assigning more than one slave address to a device (sort of bank selection) followed by a single 'register select' byte or by using two or more bytes that follow a single slave address and that are used together to form a 16 bit register selection. The first approach is used for RAM or EEPROM I2C slaves that have more that 256 byte of memory. Checkout the data sheet for this type of devices to get the details. For example the PCF8598 is an 8 kbits (1024 × 8-bit) EEPROM. Note that the regular mbed lib does not support multiple slaveaddresses. Some mbed platforms do support it (eg the LPC824). The other option with 16 bit internal address bits can be implemented with the mbed libs. You just need to encode and decode the address data accordingly. The i2c.write() uses a single slaveaddress and the first two bytes in the transmit buffer must be filled with the 16 bit register address, the third byte is the data to be written. The slave should receive and decode 3 bytes, two for the register address and one for the data.