I2C 2-Master-1-slave read/write parallelly with mutex lock

System details: LP50xx is connected to a windows/Linux host, and host is setting led colours and brightness through I2C (using this code driver: leds-lp50xx.c - drivers/leds/leds-lp50xx.c - Linux source code (v6.1.7) - Bootlin). I have an arduino, which i am connecting to the I2C same bus (host to LP50xx) and using LP50xx arduino driver to reading the led brightness and color (LP50XX/LP50XX.cpp at master · rneurink/LP50XX · GitHub).

When host is constantly changing the led brightness and color and parallelly at the same time I am trying to read those buffers through Arduino, at that time I see frequently that I2C bus is hung and my program in the arduino is stuck and does not return anything.

By further digging into the linux host code I see that they are using mutex lock to the buffer which i am trying to read

can that cause for my code to freeze up while reading the same locked buffer?
Also can i check from my arduino code if that buffer is currently locked and wait for it to be unlocked and read it ?

Welcome to the forum.

Which Arduino board are you using ?
Which LP50xx do you have ?
Can you show a photo with the wiring ?

Did you know that the I2C bus has three wires: SDA, SCL, GND.
A wire with SDA should not be next to a wire with SCL. According to the I2C standard, they can only be next to each other for 10cm.
When devices with different signal voltage levels are connected to the same I2C bus, then you might be working outside the specifications of the datasheets (for example combining 3.3V devices with a 5V Arduino board).

The "rneurink" Arduino library is in the Arduino IDE Library Manager. It does not have many stars on Github, but it was tested with different Arduino boards. I see no bugs in the code, so I assume it works.

:point_right: Two Masters on the I2C bus is bound to go wrong. Depending on the code, it can go wrong within a second up to once in many weeks.

I assume that the mutex is to prevent that multiple tasks try to control the same LP50xx led controller at the same time. I think that is the right thing to do.

The Arduino can not look into the code of the linux host. That is impossible.

The linux host might have code to check for a I2C bus collision, but the Arduino Wire library might not cover 100% of the I2C problems and the "rneurink" library is missing the basic checks for a I2C collision. If those checks were added, then a multi-Master I2C bus still would not work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.