kplindegaard / smbus2

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

Help with a software reset command #38

Open rossmacarthur opened 5 years ago

rossmacarthur commented 5 years ago

My I2C chip has a software reset command.

image

How could I implement this using smbus2? I have no problem writing to the 0x40 address using

from smbus2 import SMBusWrapper

with SMBusWrapper(0) as bus:
    bus.write_byte_data(0x40, 0x0C, 0x01)
kplindegaard commented 5 years ago

@rossmacarthur: The recipe seems to match the i2c write diagram halfway down the i2c specification.

image

What I suggest is that you modify Example 5 in the readme and supply a triplet consisting of the SWRST call, Byte 1 and Byte 2 as payload:

from smbus2 import SMBusWrapper, i2c_msg

with SMBusWrapper(0) as bus:
    # Write SWRST payload to address 1001 011
    adr = 0x4b  # 1001 011
    payload = [0x96, 0xa5, 0x5a]
    msg = i2c_msg.write(adr, payload)
    bus.i2c_rdwr(msg)

See if that does the trick.

rossmacarthur commented 5 years ago

Hmmm unfortunately it doesn't work

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "venv/local/lib/python2.7/site-packages/smbus2/smbus2.py", line 497, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
IOError: [Errno 6] No such device or address
kplindegaard commented 5 years ago

So what does i2cdetect -y 0 tell you?

rossmacarthur commented 5 years ago
$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- 4b -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- 64 -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
kplindegaard commented 5 years ago

So addr 0x4b is there. Good. But honestly, I don't see anything wrong with the payload [0x96, 0xA5, 0x5A] ... :/