Hi *,
I’m working on a Pi3 project where I need to read out 16 bit values from an I2C slave, via Python. My Pi3 B is running up-to-date Leap 15.2 and I’ve tried both Malcolm’s python3-smbus (https://download.opensuse.org/repositories/home:/malcolmlewis:/SLES12-SP2-RPI-Extra/openSUSE_Leap_15.2_ARM/) as well as the version from illuusio (https://download.opensuse.org/repositories/home:/illuusio:/python/openSUSE_Leap_15.2_ARM/)
The code seems to work fine as long as I read or write 8bit values, but in the end, I need to read out 16bit (two byte) values from the I2C slave (DS1631).
Interestingly, even reading a single byte fails if I use read_byte_data(), it only works if I use separate write_byte() and read_byte() statements:
works, although only for a single byte
self.bus.write_byte( sensoraddr, 0xaa)
tempint = self.bus.read_byte( sensoraddr)
fails with OSError: [Errno 121] Remote I/O error
tempint = self.bus.read_byte_data( sensoraddr, 0xaa)
Looking around on the net, it looks like I’m using the proper API and I even tried a Python class explicitly designed for Pi3b and this chip, which fails the same.
Might this be a problem with the kernel module driving the chip or the code layer between the Python smbus class and the lower layers?
Thank you for any advice you may be able to share.
Regards,
Jens
Hi Jens
This is the one installed: python3-smbus-4.1-lp152.3.1.aarch64.rpm? I think it only does 8bit so need to look at MSB and LSB.
Hi Malcolm,
thank you for jumping in!
These were the ones I tried:
i+ | python3-smbus | package | 4.1-lp152.3.1 | aarch64 | Pi3ByMalcolmLewis
i+ | python3-smbus2 | package | 0.2.3-lp152.1.1 | noarch | illuusio
(of course I adjusted the Python imports to work with smbus2 when testing the latter.)
> so need to look at MSB and LSB
“MSB/LSB” as in “most/least significant byte”? I believe I’ve been through any API in smbus to retrieve the values, but cannot see one that results in sending <S> addr <W> <A> 0xaa <A> <Sr> addr <R>, upon which the chip sends <A> byte1, master sends <A>, chip sends byte2, master sends <NACK> <stop>… I guessed that’s what read_word_data() was supposed to do, but how do I break that down to more basic commands in Python?
Regards,
Jens
Hi *,
just as a follow-up to the casual reader: The problems were in the end unrelated to OpenSUSE Leap, but caused by hardware. Seeing the I2C devices in “i2cdetect” does not mean that all communications will be stable, if the bus is electrically mis-aligned.
For a test, I booted PiOS on the same machine and as the requests were similarly failing, continued to further debug at the electrical layer.
Leap 15.2 fully supports the required 16bit read/writes :good:
Regards,
Jens