smbus2 icon indicating copy to clipboard operation
smbus2 copied to clipboard

Help with a software reset command

Open rossmacarthur opened this issue 6 years ago • 5 comments

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)

rossmacarthur avatar Jul 11 '19 10:07 rossmacarthur

@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.

kplindegaard avatar Jul 20 '19 08:07 kplindegaard

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

rossmacarthur avatar Jul 29 '19 07:07 rossmacarthur

So what does i2cdetect -y 0 tell you?

kplindegaard avatar Jul 29 '19 08:07 kplindegaard

$ 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: -- -- -- -- -- -- -- --

rossmacarthur avatar Jul 29 '19 08:07 rossmacarthur

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

kplindegaard avatar Jul 29 '19 08:07 kplindegaard