I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
Is there a Way to Adjust the Duty Cycle of the I2C Master Clock?
Rena Ayeras

How to manage a locked I2C bus.Image by Jan Alexander from Pixabay

Question from the Customer:

When I use Aardvark I2C/SPI Host Adapter on a board for I2C, and the pull-ups are weak (10K on board, Aardvark adapter pull-ups are not enabled), the I2C transactions work fine with 100 KHz. But if I change the bitrate to 400 KHz, I2C transactions quickly fail with status code 6 - the bus is locked. I observed that after generating a stop, it appears the Aardvark adapter holds the SDA line low.

I’ve been looking at the details of the signals, but so far, I have not yet located the cause. Do you have any suggestions of what to look for that causes bus lock?

Also, I have had no luck recovering from the bus lock condition and releasing the SDA line. I’ve tried using the Aardvark Software API command aa_i2c_bus_free, but I have had to disconnect, power cycle, and then reconnect the Aardvark adapter.

Response from Technical Support:

Thanks for your questions! The bus error is a generic error that is received from the hardware. A bus error occurs when a START or STOP condition occurs at an illegal position in the format frame.

Examples of illegal positions occur during the serial transfer of an address byte, a data byte, or an acknowledge bit. Such bus errors rarely occur - it is possible there is an incorrect configuration or condition in the setup that you are working on. We can provide information about possible causes of bus locked condition and show you how to easily release the Aardvark adapter from the bus lock.

Lockout Status

The status code for lockout is AA_I2C_STATUS_BUS_LOCKED, which indicates an I2C packet is in progress and the time since the last I2C event executed or received on the bus has exceeded the bus lock timeout. Most likely, this is due to the clock or data line of the bus being held low by some other device, so the Aardvark adapter cannot execute a start condition.

For information about other extended status codes, please refer to the section I2C Interface of the Aardvark I2C/SPI Host Adapter User Manual.

What Triggers Bus Lock

The bus lock timeout is measured between events on the I2C bus. An event can be a start condition, the completion of 9 bits of data transfer, a repeated start condition, or a stop condition. For example, if the full 9 bits are not completed within the bus lock timeout (due to clock stretching or some other error), the bus lock error will be triggered.

  • Please note: When the Aardvark adapter detects a bus lock timeout, it will abort its I2C interface, even if the timeout condition occurs in the middle of a byte transfer.
  • When the Aardvark adapter is acting as an I2C master device, this may result in executing only a partial byte on the bus.

Bus Lock Timeout

You can use an API function to set the duration of the bus lock. This way, you will no longer need to disconnect and power cycle the Aardvark adapter when a bus lock occurs.

The Aardvark API function to use is aa_i2c_bus_timeout, which sets the I2C bus lock timeout in milliseconds.

int aa_i2c_bus_timeout (Aardvark aardvark, aa_u16 timeout_ms); Arguments
aardvark           handle of an Aardvark adapter

timeout_ms    the requested bus lock timeout in ms.

Return Value
This function returns the actual timeout set.
Specific Error Codes
None.

The power-on default timeout is 200ms. The minimum timeout value is 10ms and the maximum is 450ms. If a timeout value outside this range is passed to the API function, the timeout will be restricted.

  • The exact timeout that is set can vary based on the resolution of the timer within the Aardvark adapter. The nominal timeout that was set is returned back by the API function.
  • If the bus is locked during the middle of any I2C transaction (master transmit, master receive, slave transmit, slave receive) the appropriate extended API function will return the status code AA_I2C_STATUS_BUS_LOCKED.

Additional resources that you may find helpful include the following:

We hope this answers your question. Looking for more information? You can contact us and request a demo that applies to your application, as well as ask about our Total Phase products.

Request a Demo