Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I2c that support 16 bits address

Tags:

i2c

Initially, I used a eBus SDK which supports 8 bits registers for the I2C. This SDK does not support 16 bits register address for I2C. Is there any alternative to this sdk that support 16 bit register address for the I2C?

Best wishes and thank you in advance

like image 740
ras red2004 Avatar asked Feb 16 '23 22:02

ras red2004


2 Answers

There are a few concepts to clear up based on the other comments. All I2C devices ONLY support 7-bit (8 with the read/write) and 10-bit Slave Addressing. This, however, was not the concept asked about in the topic.

I2C, per the protocol specifications, reads/writes in sets of 8-bits followed by an Acknowledgement (ACK/NACK) from the device receiving the data. How the device interprets the bits read/written to it can vary greatly from device to device.

From my personal experience, I have found that often a larger register address -- such as 0x1234 -- simply means that you need to read/write from registers 0x12 and 0x34. Both registers will hold 8-bits of information which together form the actual 16-bit word referenced by the hexadecimal 0x1234.

As I mentioned though, this can vary per device. You will likely need to read through the Data Sheets/Manuals for your specific I2C device for more information on its register addressing to ensure you read/write from the right registers and assemble the individual 8-bits into the correct order to extract the corresponding 16-bit word.

like image 124
MrHappyAsthma Avatar answered Feb 18 '23 13:02

MrHappyAsthma


As MrHappyAsthma perfectly pointed out the I2C is organized in 8-bit transfers.You must study documentation of your device. Search for something like setting internal 16-bit address with writing two bytes, and later do the read (as you mentioned one or two bytes). It would look something like this:

// register read scenario (first 0x12 will be your 8-bit API address, and you attach the 0x34 to the data part of your API)
DO WRITE: |S| slave address |W| write 0x12 | write 0x34 |S| (be careful with ordering)
DO READ:  |S| slave address |R| read 1'st byte | read 2'st byte |S| (if 16-bit data)

// register write scenario  (first 0x12 will be your 8-bit API address, and send 3-bytes of data, where first byte is your LSB address)
DO WRITE: |S| slave address |W| write 0x12 | write 0x34 | write data 1'st byte | write data 2'st byte |S| (if 16-bit data)

Check documentation for you slave device. If you are able to use your API to force such transfers you can trick the device to give you what you need.

like image 43
Knight of Ni Avatar answered Feb 18 '23 13:02

Knight of Ni