I2C bus error when using _threading
-
Hi! I'm reading a couple of sensors using a function I call
sensor_read()that then updates some global variables. When running it non-threaded, reading one bus at a time, I get no errors. However, when trying to read two buses (on the same pins) at once, I get I2C Bus Error from both of the devices I am trying to read data from.How can I solve this? Is there any particular reason for why the function works non-threaded but not threaded?
-
@techykermit I assume that both threads try to use the bus at the same time. That is not possible. So you must serialize the access, e.g. by using a semaphore. For that, the _thread class provides the lock methods. Note that the acquired lock has to be a global object visible to both threads.
-
@robert-hh said in I2C bus error when using _threading:
@techykermit I assume that both threads try to use the bus at the same time. That is not possible. So you must serialize the access, e.g. by using a semaphore. For that, the _thread class provides the lock methods. Note that the acquired lock has to be a global object visible to both threads.
Aha, I see. I will look into the lock method then, thank you for your help!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login