question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Ack Polling for I2C

See original GitHub issue

When writing to an EEPROM (Microchip 24LC256), the device goes into a “busy” state for a few milliseconds when a page of data has been written. It is possible to “poll” the device to determine when it has finished by essentially performing a zero byte write, essentially meaning that the device address is sent on the bus, then if the device is ready it will acknowledge (ACK) and if it is not ready it will not acknowledge (NACK).

The issue is that there needs to be a way to poll the device to determine whether it is ready for the next command.

Ideal solution: add the following method to I2cDevice: bool AckPoll(), which sends only the device address on the bus and returns a boolean matching the ACK/NACK state. This can then be read in a tight loop to determine when the device is ready. Could probably also be implemented as an awaitable async method with a timeout to do background polling, but the simple implementation is fine.

Note: I am not using the underlying OS support for I2c via I2cDevice.Create(), I have derived from I2cBus and I2cDevice to implement a Serial to I2C converter that works on any OS, so all my testing so far has been done using this running on Windows 10. The trivial implementation below works, in that a zero byte write that is not acknowleged by the device throws an exception stating “NACK on address” - it just takes too long to throw/catch the exception longer than the busy time of the device), hence the need for a proper AckPoll method that doesnt rely on catching exceptions (I am assuming that the OS support for I2C works in the same way):

bool AckPoll()
{
    try
    {
        i2cDevice.Write(new byte[0]);
        return true;
    }
    catch
    {
        return false;
    }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
pgrawehrcommented, Dec 22, 2021

Regarding your last point: We’re kind of having a hard time continuing to support Windows IOT. It officially only works on the Pi3 and has never been updated to the Pi4. Event the upcoming Windows 11 for ARM is (as it currently looks) not supported on the Raspberry Pi (any version). The information you find about it is very poor. Advertisements and “developer resources” everywhere, but no operating system image to download and test.

I therefore think we currently don’t have to worry about windows support, but maybe @joperezr can get some information about whether there will one time be a new Windows Version for a Raspi (or a similar device).

1reaction
joperezrcommented, Apr 15, 2021

[Triage]: This feature is approved. We would like the API to look like the following:

    public abstract partial class I2cBus : IDisposable
    {
       //..
+      public virtual bool IsDeviceReady(int deviceAddress);
    }

    public abstract partial class I2cDevice : IDisposable
    {
       //..
+      public virtual bool IsDeviceReady();
    }

@philrawlings would you be interested in contributing a PR for this addition?

Read more comments on GitHub >

github_iconTop Results From Across the Web

I2C (TWI) Acknowledge Polling Support on the Atmel SMART
I2C Acknowledge Polling feature is used for detecting the completion of write cycles after the byte write and page write operations. This allows ......
Read more >
I2C EEPROM ACK polling - Forum - RA MCU
I am using the I2C Communicatons Middleware and I2C Master on IIC to access a 24xx08 EEPROM device on one of the I2C...
Read more >
I2C Acknowledge Polling - ST Community - STMicroelectronics
Solved: The eeprom I am using has no status byte/bit. In order to know if the device is busy you have to look...
Read more >
I2C without ACK - C2000 microcontrollers forum - TI E2E
Is it possible to use I2C network on TMS320f28335 without wait for the slave ACK bit? Thanks, ... TMS320F28379D: Ack polling in I2C...
Read more >
I2C polling and ACK/NACK checked in next command
Dear all, I am struggling with I2C bus and reading measurement from SHT30 sensor. I am able to read serial number and status...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found