-
Notifications
You must be signed in to change notification settings - Fork 571
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
Support for I2C flags to hold SDA low (Unix) #2160
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
Priority:2
Work that is important, but not critical for the release
Comments
ypedegroot
added
the
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
label
Nov 8, 2023
ghost
added
the
untriaged
label
Nov 8, 2023
krwq
added
Priority:2
Work that is important, but not critical for the release
and removed
untriaged
labels
Nov 9, 2023
ghost
removed
the
untriaged
label
Nov 9, 2023
It may not be the perfect solution, but you can also switch a pin between i2c and GPIO. Try something like the following: Board b = Board.Create();
var controller = b.CreateGpioController();
controller.OpenPin(2, PinMode.Output); // The SDA pin of the default I2C bus
controller.Write(2, PinValue.Low);
Thread.Sleep(10);
controller.Write(2, PinValue.High);
controller.ClosePin(2);
var bus = b.CreateOrGetI2cBus(1);
var device = bus.CreateDevice(deviceId);
// ... Use device, should have been woken up Using the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
Priority:2
Work that is important, but not critical for the release
Is your feature request related to a problem? Please describe.
I have a Raspberry Pi Compute Module 4 based carrier board that also contains an I2C slave device that needs to be woken up by holding SDA low for at least 75 uS. When the Raspberry Pi's I2C bus runs at 100 kHz, opening a write to 0x00 pulls the SDA low long enough to wake-up the slave. However, this is no longer feasible when the I2C bus runs at 400 kHz; then, the SDA is only pulled low for approximately 25 uS, which is too short.
The problem is that the I2C driver by default stops the transaction when a NAK occurs (which obviously occurs when writing to 0x00, an invalid I2C address). However, Raspberry Pi recently introduced support for the I2C I2C_M_IGNORE_NAK flag (see this commit: raspberrypi/linux@8c4f88c).
Describe the ideal solution
In our implementation, we use the System.Device.Gpio package in combination with the LibGpiodDriver. It would be nice if support for i2c_msg "flags" would be added, so a slave device requiring a low SDA for a longer time than 25 uS to wake up can be woken up nicely.
There are only two alternatives:
See this for more information on the I2C_M_IGNORE_NAK flag: https://www.[kernel.org/doc/Documentation/i2c/i2c-protocol](https://www.kernel.org/doc/Documentation/i2c/i2c-protocol)
In the Discord i2c-discussions thread, @Ellerbach suggested to take a look at the files https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/I2c/UnixI2cBus.cs and https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/I2c/UnixI2cFileTransferBus.cs.
In those files, before the I2C action is executed, the flags are being set.
Perhaps it would be good to introduce an overload function on the Write (and/or Read) functions to add additional flags to an I2C operation. Another idea is to add a method to hold the SDA low for a specified amount of time. A final suggestion would be to expose a property in which the I2C flags can be set.
The text was updated successfully, but these errors were encountered: