Skip to main content
Visitor II
June 12, 2024
Question

I2C - Delay between address byte and first data byte when reading

  • June 12, 2024
  • 4 replies
  • 3229 views

Hi,

is there anyway to insert a delay between the start generation address byte transmission and the first data byte reception from the slave device? I have tried reading 0 bytes from the slave to prevent the reading of the first byte but that sets the Transmission Complete bit which can only be cleared by another Start condition, which puts me back on square one.

BR

Goran

    This topic has been closed for replies.

    4 replies

    Super User
    June 12, 2024

    Yes, this is called "clock stretching". Read on this in I2C documentation.

     

    GoEkAuthor
    Visitor II
    June 12, 2024

    I may have been unclear, what I mean is to, as a master doing a read of a slave device, on the MCU side put in a delay between the start/address byte and the first data byte read. My slave device does not have clock stretching but  instead requires "a 100us delay between all bytes (including address byte) that is read/written over the bus". If it is unhappy it simply NACKs if it is too busy, anywhere in the ongoing transmission.

    Graduate II
    June 12, 2024

    What slave device is this? That is a very unusual requirement.

    GoEkAuthor
    Visitor II
    June 13, 2024

    TI MCT8316A. They realize this is a fault and "it will be fixed in the next chip revision" which doesn't help me since it is already used in hundreds of products.

    Super User
    June 13, 2024

    This is unusual, but just simply make the delay. The master drives the clock. Just do not drive it for the needed time. If no existing library function does this, just write your own.

     

    GoEkAuthor
    Visitor II
    June 13, 2024

    Got it all working except there seems to be no way to get the I2C port, during a read, to halt after the address byte. I can read 0 bytes and the I2C terminates with the Transfer Complete ISR bit set. Unfortunately, the only way to clear that bit is by issuaing a Start or a Stop condition which is not what I want.

     

    I also tried using the Reload functionality which instead sets the TCR bit which CAN be cleared but if I set the RELOAD bit during a 0 byte read, the TC flag still gets set.

    Visitor II
    November 16, 2024

    Hello,

    Did you ever find a solution to this?

    I have a device that also requires this delay. I have come to the same conclusion that there does not seem to be a way to either interrupt or delay between writing the address and then reading the bytes. Did you have any luck finding a method?

    Thanks.

    Graduate II
    June 13, 2024

    You could always bit-bang the bus, or just have some timed callback after each byte, ie gets the IRQ,and sets up a deferred processing task.

    GoEkAuthor
    Visitor II
    June 13, 2024

    Tried that, I all works except for reads where I have no way of inserting the delay between the address and first data byte.