10 Replies Latest reply on Jan 31, 2014 7:08 AM by user_1377889

    Posible interaction between ADC_SAR_Seq and I2C

    amaza

       I've a project with I2C (slave and fixed function) and an ADC_SAR_Seq with many differential inputs (about 20).

         

      ADC works perfect without cpu work (only to get values after a complete conversión of the 20 inputs).

         

      But I2C doesn't work, the master says BUSY. After a while of testing and retesting I've tested omit ADC_SAR_Seq_StartConvert(); and voilá, I2C works perfect.

         

      First I thought about high SPS, so down it. but no improvement, only omiting StartConvert solves the I2C problem.

         

       

         

      Also commenting code into ADC ISR solves the problem and I2C begin to work. 

         

       

         

      The code for the I2C is simple and it's into the for loop:

         

      if(0u != (I2C_SlaveStatus() & I2C_SSTAT_WR_CMPLT))

         

      {

         

      /* Read the number of bytes transferred */

         

      byteCnt = I2C_SlaveGetWriteBufSize();

         

      /* Clear the write status bits*/

         

      I2C_SlaveClearWriteStatus();

         

      /* Move the data written by the master to the read buffer so that the master can read back the data */

         

      for(indexCntr = 0; indexCntr < byteCnt; indexCntr++)

         

      {

         

      rdBuf [indexCntr] = wrBuf[indexCntr]; /* Loop back the data to the read buffer */

         

      }

         

      /* Clear the write buffer pointer so that the next write operation will start from index 0 */

         

      I2C_SlaveClearWriteBuf();

         

      /* Clear the read buffer pointer so that the next read operations starts from index 0 */

         

      I2C_SlaveClearReadBuf();

         

      }

         

      /* If the master has read the data , reset the read buffer pointer to 0 and clear the read status */

         

      if(0u != (I2C_SlaveStatus() & I2C_SSTAT_RD_CMPLT))

         

      {

         

      /* Clear the read buffer pointer so that the next read operations starts from index 0 */

         

      I2C_SlaveClearReadBuf();

         

      /* Clear the read status bits */

         

      I2C_SlaveClearReadStatus();

         

      }

         
              
         

      Again the code into the isr is simple:

         

      CY_ISR( ADC_SAR_Seq_ISR )

         

      {

         

      int i;

         

        for( i=0;i<20;i++)

         

      {

         

      ichannels[i] = ADC_SAR_Seq_GetResult16(i);

         

      }

         

      }

         

      Best regards.