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.

TMS320C6670 I2C driver

Hi all,

I'm currently working with I2C driver on 6670. The problem I encountered was i couldn't detcct the clock signal on the SCLK pin. First, I put the I2C module in reset

state. Then set the prescaler of the clock and take the module out of reset. What's more, fill the ICCNT and ICSAR registers, set 6670 in TX, master and free mode.

Finally, generate start singal. And the ICDXR with data I want to write to EEPROM. But I couldn't get clock on the corresponding pin. What's wrong with the process of

configuring this module?

The following is part of the program:

CSL_I2cRegs t_I2cRegs;

void i2c_set_opt(void)
{
 /*Master mode. The I2C is a master
   and generates the serial clock on the SCL pin.*/
 t_I2cRegs.ICMDR  = 0;
 t_I2cRegs.ICMDR  = t_I2cRegs.ICMDR|
   (1<<CSL_I2C_ICMDR_MST_SHIFT)|
   (1<<CSL_I2C_ICMDR_FREE_SHIFT);
 t_I2cRegs.ICPSC  = 0x319;
 t_I2cRegs.ICCLKL = 0x02;
 t_I2cRegs.ICCLKH = 0x02;
 t_I2cRegs.ICMDR  = t_I2cRegs.ICMDR |
  (1<<CSL_I2C_ICMDR_IRS_SHIFT);
}

void i2c_tx_fn(UINT8 uwslaveaddr, UINT8* puwdata, UINT16 uwlen)
{
 UINT8 i;
 t_I2cRegs.ICCNT = uwlen;
 t_I2cRegs.ICSAR = uwslaveaddr;
 t_I2cRegs.ICMDR |= ICMDR_STT + ICMDR_TRX + ICMDR_MST + ICMDR_IRS + ICMDR_FREE;
 delay_cycles(10);

 for(i = 0; i < uwlen; i++)
 {
  t_I2cRegs.ICDXR = puwdata[i];
  while((t_I2cRegs.ICSTR & ICSTR_ICXRDY) == 0)
  {
   ;
  }
 }
 delay_cycles(100);

 t_I2cRegs.ICMDR |= ICMDR_STP;

 /*polling ACK*/
 t_I2cRegs.ICSAR = uwslaveaddr;
 t_I2cRegs.ICMDR |= ICMDR_STT + ICMDR_TRX + ICMDR_MST + ICMDR_IRS + ICMDR_FREE;
 while(t_I2cRegs.ICSTR & ICSTR_NACK)
 {
  ;
 }
}

Thanks

Best regards

Nick

  • Hi Nick,

    The below portion is an example setup function for I2C you can use as reference for initialization:

    void init_i2c(void)
    {

      //Bringing up the I2C in enable mode
    //  I2C_RSET(PSVR_LCKREG,  PSVR_LCKVAL);  // write in Lock register - 0x0F0A0B00
    //  I2C_RSET(PSVR_MDCTL0,  PSVR_I2CEN);   // Get I2C in enable mode - 0x00001000
    //  I2C_FGET(PSVR_MDSTAT0, 18) ;           // check whether I2C is out of power down
    //  while (fieldval == 0) I2C_FGET(PSVR_MDSTAT0, 18) ;

      // It's assumed that, I2C is enabled on reset, & SDA, SCL are I2C func pins.
      I2C_RSET(I2C_OAR,  0x000002AA);  // Sets its own address
      I2C_RSET(I2C_IMR,  0x00000000);  // Configure for no interrupts, mask the interrupts
      I2C_RSET(I2C_CLKL, 0x00000065);  // ConfigureI2C_CLKL reg
      I2C_RSET(I2C_CLKH, 0x00000065);  // ConfigureI2C_CLKH reg
      I2C_RSET(I2C_CNT,  0x00000001);  // Clear the data count reg.(ICCNT),ICCNT=1
      I2C_RSET(I2C_SAR,  0x0000001E);  // Address of the communicating slave.
      I2C_RSET(I2C_PSC,  0x00000001);  // Configure I2C_PSC reg.
      I2C_RSET(I2C_MDR,  0x00000020);  // Bring I2C out of reset.
    }

    Let me know if this helps.

    Regards,
    Sahil

  • Hi Sahil,

    Thank you for your detailed information. It helps me a lot.

    Thx

    Best regards,

    Nick

  • Nick,

    That's great to hear. Let me know how the progress goes. 

    Regards,

    Sahil