I am using my own processor and SMBUS2 to communicate with an external device over i2c. I have to follow the procedure below to be able to read the IDCODE of the device. Is it possible in smbus2 to have start and stop conditions as you wish?
I2C start | 7-bit I2C ADDR+write bit | slave ACK | 1st byte | slave ACK | 2nd byte | slave ACK | 3rd byte | slave ACK | 4th byte | slave ACK and then NO stop bit, rather...
I2C start | 7-bit I2C ADDR+write bit | slave ACK | 1st byte | slave ACK | 2nd byte | slave ACK | 3rd byte | slave ACK | 4th byte | slave ACK | and again NO stop bit, rather...
I2C REstart | 7-bit I2C ADDR+READ bit | slave ACK | 1st byte | Master ACK | 2nd byte | Master ACK | 3rd byte | Master ACK | 4th byte | Master ACK | I2C STOP
My understanding is that the method write_i2c_block_data(...) puts start and stop conditions automatically so it wouldn't quite work to create the flow above. I see the methods read_byte() and write_byte() which maybe just sending bytes without the start and stop, but then what is way to send start and stop bytes. I tried the following but doesn't work.
# start
bus.write_byte(I2C_ADDRESS, 0x00)
wait_for_ack()
for byte in Bytes:
bus.write_byte(I2C_ADDRESS, byte)
wait_for_ack()
# stop
bus.write_byte(I2C_ADDRESS, 0xFF)
Here wait_for_ack() is something like this,
ack = bus.read_byte(I2C_ADDRESS)
if ack == 0x00:
print("ACK received.")
Like Ian commented, the way to do it is to use the .i2c_rdwr() method. Here is an example,
I was also hoping to find a way to send start and stop condition manually so that I can program the device over I2C from a file. For that I guess I have to do just do some bit-banging.