4

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

ras red2004
  • 169
  • 1
  • 1
  • 10
  • 3
    I2C is an embedded bus, found on many different chips. It doesn't even have 8 bit addressing (last bit is not an address bit but R/W bit). I''m quite confused what your problem actually is. – MSalters Jul 16 '13 at 19:14
  • 3
    If I understand you correctly, you want to read 16-bits of data via I2C? Normally devices will just use 2 registers to store 16-bits. I.E. Register 0x00 will be the least significant bits (LSB) of Data. Register 0x01 will be the most significant bits (MSB) of Data. You can append these together to get the full 16-bit register. What device are you communicating with and did I understand you correctly? – MrHappyAsthma Jul 16 '13 at 19:28
  • @MSalters: I am sorry for not being so clear. I have a device that i need to read its registers via I2C bus. These registers have addresses represented by 16 bit (e.g. 0x1234). The value of these registers are either 8 or 16 bits ( stored over one or two registers). – ras red2004 Jul 17 '13 at 11:21
  • @MrHappyAsthma: you understood me correctly. However, the register address in this device is represented by 16 bits not 8 bits, while the eBus SDK only allow addressing registers with 8 bits addresses. In other words: register address = 0x1234, register value = either 0xab or 0xabcd. – ras red2004 Jul 17 '13 at 11:21

4 Answers4

6

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.

MrHappyAsthma
  • 6,332
  • 9
  • 48
  • 78
3

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.

Knight of Ni
  • 1,780
  • 3
  • 20
  • 47
0

It seems to be impossible for some to understand what difference is between I2C external address, internal address and data.

The original question is simply "How to read/write to a I2C register, whose INTERNAL ADDRESS is 16bit ?"

smbus handles only 8 bit internal addresses. So it is impossible to read/write but first 256 bytes of a I2C EEPROM.

There is a lot of talk about at24, but so far I have not found anything describing how to use it or even install.

Risto
  • 1
0

Nine years gone after the original question and still there has been no way to address 16bit REGISTER addresses. Everybody understand allready the difference between device and register addresses. Please stop repeating the comments about '7bit address and one R/W bit', when somebody asks about 16bit addressing.

This should be handled by the Linux kernel specialists, because there is so much large I2C memories. For example I myself am fighting with a bed of FeRAM chips. The next thing is to move the bed to general IO-pins of RasPi and write the whole program from scratch.

Cordite
  • 11
  • 1