Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4810

Interfacing (DSI, CSI, I2C, etc.) • Multiple processes accessing an i2c device

$
0
0
I have a Raspberry Pi Zero 2 w. I am new to Raspberry PI OS, but very familiar with Linux. It seems that devices on the I2C bus are accessed from user space through character device /dev/i2c-1 after some setup to allow non-root users to access the bus.

It seems you access a device on I2C by using system call open() and then use ioctl to set the device's address on the bus. Then you can make reads and writes to that file handle to exchange data with the device on the I2C bus.I gleaned this from this https://github.com/Wicker25/Rpi-hw/blob ... er/i2c.cpp

My question is how do I handle access to the i2c device if I have multiple processes that want to talk to devices on the I2C bus at the same time?

Does the /dev/i2c-1 device only allow 1 open at a time ? That would seem to prevent collisions.

If that is the case is there an option to open() so that the second process won't immediately return an error but wait in the open() waiting to get the device once the other one closes it?

I would hate to have to have the second request return immediately with a fail and then have to sleep and try again later.

Thanks
Chris

Statistics: Posted by chriskot870 — Sat Jun 15, 2024 4:01 am



Viewing all articles
Browse latest Browse all 4810

Trending Articles