kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
243 stars 68 forks source link

the return value of i2c_rdwr() function #88

Closed davesliu closed 1 year ago

davesliu commented 1 year ago

Hello

I want to use the i2c_rdwr() funciton to simulate the SMBus block process call as currently the raspberry pi 4 (BCM2711 chip) doesn't support the SMBus block process call in its driver level.

Just want to write two bytes data 0x1,0x11 to register 0x10 at address 0x50 and then tried to read back the data address 0x20. It seems that below operation doesn't work. Could you help to see if there is any restart between write_data and wrtie_data2? and is there any restart bit betwen wrtie_data2 and read_data?

bus = smbus2.SMBus(1)
write_data = smbus2.i2c_msg.write(0x50,[0x10,0x2,0x01,0x11])  # write some data as block write, 0x10 is the register address, 0x2 is data length, 0x1 and 0x11 is to be written data.
wrtie_data2 = smbus2.i2c_msg.write(0x50,[0x20])  # write the register 0x20 for data reading
read_data = smbus2.i2c_msg.read(0x50,4)  # specifiy the lenght of 4 bytes data to be reading at 0x20.
bus.i2c_rdwr(write_data,wrtie_data2,read_data)
kplindegaard commented 1 year ago

Hi @davesliu. Interesting hack you propose there. I have unfortunately no experience to lean on in this particular matter, but you may want to take a look compare Figure 17 with Figure 3 in the Interfacing I2 C* Devices to an Intel® SMBus Controller from Intel. It seems to me you should try to combine the two write operations into one (with some adjustments too, perhaps?).

davesliu commented 1 year ago

@kplindegaard Yes, you are right, I just want to implement the "SMBus Block Write-Block Read Process Call" as shown in Figure 17 of that document.

But it seems not work.