Other Parts Discussed in Thread: SPRC191, TMS320F2808
Hi,
I'm having some problems with the I2C protocol on the tms320f2808. In fact i only want to write 4 bytes to a slave µC. I have been using the example of sprc191, however the bit I2caRegs.I2CSTR.bit.BB never goes to 0.
The init routine is like that:
void InitI2C(void)
{
//I2caRegs.I2CMDR.all = 0x0000;
// Initialize I2C
I2caRegs.I2CSAR = 0x0002; // Slave address - EEPROM control code
I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
I2caRegs.I2CIER.all = 0x24; //0x24 // Enable SCD & ARDY interrupts
I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended
I2caRegs.I2CMDR.bit.IRS = 1;
I2caRegs.I2CFFTX.all =0x6000; // Enable FIFO mode and TXFIFO
// I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1;
bufCheck[0]=251;
bufCheck[1]=3;
bufCheck[2]=0;
bufCheck[3]=234;
}
And the write routine:
int Escribir_I2C(Uint16 Dir_I2C,unsigned char *buf, Uint16 len)
{
Uint16 i;
while (I2caRegs.I2CMDR.bit.STP == 1); // Wait for Stop condition bit to be zero.
while (I2caRegs.I2CSTR.bit.BB == 1); // Wait for Bus Busy to be zero.
// I2caRegs.I2CMDR.all = 0x0000;
// Setup slave address
I2caRegs.I2CSAR = Dir_I2C;
// Setup number of bytes to send
// MsgBuffer + Address
I2caRegs.I2CCNT = len;
for (i=0; i<4; i++)
{
I2caRegs.I2CDXR = buf[i];
}
I2caRegs.I2CMDR.all = 0x6E20;
// Send start as master transmitter
return 0;
}
If somebody have any ideas i will be gratefull. thx.