kplindegaard / smbus2

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

How to do repeated starts #25

Closed chetferry closed 5 years ago

chetferry commented 5 years ago

I am attempting to do the following with a Raspberry pi zero w:

start condition

address+write bit write byte

start condition

address+read bit read byte read byte read byte

stop condition

Can you suggest the right combination of calls using the smbus2 library?

I am successfully talking on the bus. I can see with my logic analyzer the device ACK. I have failed thus far to figure out how to do the write one byte, send another start then a read command then read the 3 bytes. I can do all kinds of other communication just fine using the smbus2 library. Thanks in advance for any help that could be provided.

kplindegaard commented 5 years ago

Have you tried setting up an "i2c_rdwr" combination similar to one in example 6?

from smbus2 import SMBus, i2c_msg

# Transaction writing one byte then reading three bytes
addr = 80
output_byte = 45  # Byte value to write
write = i2c_msg.write(addr, [output_byte,])
read = i2c_msg.read(addr, 3)
bus = SMBus(1):
bus.i2c_rdwr(write, read)
bus.close()

# Convert read message to a list and print it
data = list(read)
print(data)
kplindegaard commented 5 years ago

@chetferry any updates?

kplindegaard commented 5 years ago

Recipe given so I'm closing this one.