This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Slow response time for I2C_write

Hi,

I'm using the CSL to control the Maxim 9856 codec over I2C interface from my C5502. I've been using it for a while to initialise the codec into the required state and all works fine. However now I want to control a register in real time to implement an AGC and am noticing that the call to I2C_write() is taking of the order of 1.3ms (approx 380,000 clock cycles). This is causing serious problems with my real-time performance.

I've noticed that I'm only running the I2C at half the maximum clock rate according to the Maxim datasheet. I hope this will decrease the processing time, but even with a 50% increase I'll still experience a 650us delay that I'd rather not have,

Is there a way to use the I2C_write function (or any other function) to write to the I2C without incurring a delay, and receiving the return code via asynchronous callback (i.e. the XRDYINT interrupt)?

The I2C is operating in master mode, using SADP transfer and writing 2 bytes. The config uses 7-bit address mode with 8 bits/byte. The current clock rate is 200kHz, which I shall try increasing to 400kHz.

Thanks.

Chris

 

  • Looks like I'm answering my own question here. Have looked at the code in the CSL for I2C_write, and there are enforced unconditional delays of 32,000 clock cycles per byte (except the last) and 320,000 clock cycles at the end of the message whilst it waits to check for a NACK. For two bytes, that's 352,000 clock cycles of NOPping.

    Now I'm assuming that there is a damn good reason for all this NOPping about, but it looks to me as if I need to carefully craft a new version of the function that doesn't have >1ms of NOPping, but maybe performs the check of the NACK bit later asynchronously. Or just doesn't bother.

    Opinions?

    Gist of the function included below.

      for (k=1;k<length;k++)  {   /* enter main loop for transmitting data */
           
          
          for (i=0;i<32000;i++)  {  /* delay loop */
          asm (" NOP");
          }
                        
       /* Check for NACKs, tx ready bit */

       ...

       /* Write data byte */

       ...

     
       for (j=0;j<10;j++) {    /* last delay loop for last data transferred*/
          for (i=0;i<32000;i++)  {
          asm (" NOP");
          }
        }

     

     

  • Took out all the delays, and still seems to work fine but a lot quicker than before.

    Problem solved.

    Thank goodness for forums.