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.

I2C confusion

Other Parts Discussed in Thread: TMS320F2806

Hi everyone, I've got a question. Are all the acknowledgments handeled by the TI uC itself or do I have to implement ACK in my code too. I have tried to establish communication over I2c. Just read some register, thats it. Instead of using interrupts, I am checking if the rxfifo of ic2 contains any bytes or not, but unfortunatelly the whole process doesn't work out as expected. I have used code from the TI example, only the main .c file has been changed as can be seen below. (TMS320F2806)

Thanks,

//initialization before main

void I2CA_Init(void)

{
// Initialize I2C
//0101111(1) = 0x5F
//0101111 = 0x2F
I2caRegs.I2CSAR = 0x005F;//0x0050; // Slave address - EEPROM control code

#if (CPU_FRQ_100MHZ)
I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk
#endif
#if (CPU_FRQ_60MHZ)
I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk
#endif
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
//I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts

I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended

I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,

return;
}

//******************************************************
//send read request
unsigned int I2CA_ReadData_2(void)
{
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return 1;
}

// Slave address 0101111 plus 1 for read -> 0101111(1) = 0x5F as address
I2caRegs.I2CSAR = i2c_slave_address;

if (I2caRegs.I2CSTR.bit.BB == 1)
{
return 2;
}

 I2caRegs.I2CCNT = 1;
    I2caRegs.I2CDXR = 0x3F;

I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address

var = 2;

return 3;

}


//*******************************************************
main
{
.
.
.
// Endless loop
for(;;)
{

// Check if data in rxbuffer
// Here checkRxfifo is always 0 as declared, means actually no data is ever received by uC

if(I2caRegs.I2CFFRX.bit.RXFFST)
{
checkRxfifo = I2caRegs.I2CDRR;
checkRxfifo_2 = checkRxfifo;
}


if(var == 1)
{
return_readData = I2CA_ReadData_2();
return_readData = return_readData;
}
}

}//main



By the way, do I have to switch from transmitting mode to receiving mode manually (I2CMDR register, bit TRX), or is it done by uC ??
  • sir,

    i am new to i2c ,i am having the similar doutes like you,my intention is to read and write data from the eeprom.if you have succeeded with it please provide me the modifications in the code .please send the code to my mail id chakrin73@gmail.com or chakri.smart@gmail.com. please sir its an urgent .guide me sir pls

  • Hi Chakravarthi,

    unfortunatelly i is quite some time back when I've worked with it. I dont have code anymore :(

    But as I remember, it was just some small thing you have to take care of. So far I remember the configuration above was actually almost correct. Jusp play with it around a bit.

  • thanks a lot sir.with your help i learned some thing ,but still some doutes sir,

    i) where can i find the received data ?

    ii)when i connected pin 9 (scl) to scope i cant find any thing?? why so??

    iii)when i connected pin 13 (sda) to scope i cant find any thing?? why so??

    iv) does it require any external connections ( i connected my eeprom sda,scl,gnd directly to the control stick)?

                                           once again thanks a lot for your quick reply sir,,,,,,,,,,,,,,,,,,,,,,,,,