-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in smbus2 for long time operation vs. pigpio and tools i2cset(get) #101
Comments
Hey and thanks for your interest in this lib. It seems your first two scripts open and close the bus for every command while the one using However, if you write your 3rd app to do the same, constantly open and close the bus, I would assume it could run forever. #!/usr/bin/python
from smbus2 import SMBus
import time
from crc import Calculator, Crc8
import random
# bus = SMBus(3) # This automatically opens the bus and keeps it open. Not recommended.
crc=Calculator(Crc8.CCITT)
downSTM=0x09
upSTM=0x0c
def command(address,command,data1,data2):
crcSum=crc.checksum(bytes([command,data1,data2]))
data=bytes([data1,data2,crcSum])
# Commented out your original code that keeps the bus open indefinitely
# bus.write_i2c_block_data(address,command,data,False)
# time.sleep(0.01)
# res=bus.read_i2c_block_data(address,command,3,False)
# time.sleep(0.01)
# Rewrite: Open and close for each command. For example like this:
with SMBus(3) as bus:
bus.write_i2c_block_data(address,command,data,False)
time.sleep(0.01)
res=bus.read_i2c_block_data(address,command,3,False)
time.sleep(0.01)
while True:
# .... As before Not tested, but I hope you get the idea. |
I've prepared 3rd app as you said (exactly the same code as yours) and unfortunetly after three hours I got the same error. |
Meaning it's the
It's hard to say why without more information. I mean, could be be that the slave device that gives in and it just accidentally happens with in this app? After all, all smbus2 is just a wrapper on top of the
Thanks for your time. |
|
Reply for "And what if you increase the sleep-interval?". I changed delay from 0.01s to 0.1 in two lines in |
Hi @msawicki-poland and thanks for your patience as well as your comments. |
Configuration:
Master i2c: Raspberry Pi Zero v2, Raspberry Pi OS
Slave i2c: two STM32s (addresses: 0x09 and 0x0c)
App for master: in infinity loop write to slave command (1 byte) with data (2 bytes + 1 byte CRC) and after it read the answer (2 bytes + 1 byte CRC).
I've prepared three versions of app:
and
Apps 1 and 2 works correctly for eg. 48h. App 3 works correctly only for two-three hours and after that app threw error:
For each app I've repeated experiment three times. Is there any bug in smbus2?
The text was updated successfully, but these errors were encountered: