I'm trying to connect my energy measurement IC with Raspberry Pi 3B using the I2C protocol. I'm using sudo i2cdetect -y 1
to detect the connected devices and it is correctly showing the address(7-bits) of the connected IC.
The IC contains a various registers of 8,16,24 and 32-bits. The register addresses are 16-bits long and I'm using the following code to access a register 0x021C(24-bits)
and write registers 0xFE(8-bit) and 0x0120(16-bit)
Python Code
from smbus2 import SMBus
bus = SMBus(1)
address = 0x38
bus.write_byte_data(address,0xFE,0xAD) #Writing single byte of data
bus.write_i2c_block_data(address,0x120,[0x00,0x30]) #Writing multiple bytes of data to the register
block = bus.read_i2c_block_data(address,0x21C,3) #Reading multiple bytes of data from the register
print(block)
bus.close()
The output should be [0x8D,0xXX,0xXX]
but the code is producing output as [0,0,0]
- Question-1: Is giving 16-bit address allowed in this Library or not?
- Question-2: If allowed then why the code is not working?
Any help would be much appreciated