On Sat, 23 Nov 2019 09:55:15 +0100, "R.Wieser" <add...@not.available>
wrote:
The Linux API seems to expose what you need. See:
https://www.kernel.org/doc/html/v4.14/driver-api/i2c.html
There are functions:
lock_bus
Get exclusive access to an I2C bus segment
trylock_bus
Try to get exclusive access to an I2C bus segment
unlock_bus
Release exclusive access to an I2C bus segment
That was after a few minutes Googling.
That was the easy bit. However, you don't say what cable lengths or
electrical environment you will be working with. I2C hardware is
*very* sensitive to electrical noise. Software bit-banged drivers tend
to be much more tolerant, so the idea of just using a pair of GPIO
pins has merit.
A client of ours produces train control systems. They spent a few
weeks writing a supposedly bullet-proof hardware driver for a deep
embedded CPU. On test, it failed (but recovered) more than once per
hour. On reverting to the bit-banged driver we had already supplied,
they saw no failures in more than two weeks.
Except for memory devices, most I2C chips change the bus direction
very frequently (every few bytes). If you want to use an unsupported
device, I suggest you do it from scratch, mmap() the GPIO port, and
read/wite the pins yourself. This has the downside of requiring you to
use sudo to run the program, but the upside that even the klunkiest
bit of coding should be able to toggle bits at tens of megahertz.
Stephen
--
Stephen Pelc,
ste...@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel:
+44 (0)23 8063 1441, +44 (0)78 0390 3612
web:
http://www.mpeforth.com - free VFX Forth downloads