I have a piece of code that sends commands to a board using the i2ctransfer
command.
This command is called inside python using subprocess.Popen
and I'm rewriting the code to use some builtin python package like smbus, however I'm having difficulties implementing it so it sends the same data.
Currently the commands are generated like this:
command = ['i2ctransfer', '-y', self.i2cbus, 'w12@' + device_address] + data
rx = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
rx_buffer = rx.communicate()
And a example of the command is:
['i2ctransfer', '-y', '1', 'w12@0x03', '0x23', '0x04', '0x49', '0x74', '0x24', '0x00', '0x23', '0x05', '0x49', '0x74', '0x24', '0x00']
Basically is sending to the device with address 0x03 twelve bytes. This command updates two registers with a single instruction:
The two first bytes is the address: 0x2304 followed by 4 bytes of data 0x49742400
After that again 2 bytes of address: 0x2305 followed by 4 bytes of data: 0x49742400
I tried using write_i2c_block_data, but I'm confused about the parameters, I dont want to directly write into a register, I just want to send an array of bytes and the board itself will parse this data into register address and register value.
import smbus
bus = smbus.SMBus(1)
device_address = 0x03
bus.write_i2c_block_data(device_address, 0, [0x23, 0x04, 0x49, 0x74, 0x24, 0x00, 0x23, 0x05, 0x49, 0x74, 0x24, 0x00])
But I'm just getting a
IOError: [Errno 121] Remote I/O error
How can I just send my array of values to device 0x03 using smbus?