Other Parts Discussed in Thread: C2000WARE
Tool/software: Code Composer Studio
Hello all,
I worked with I2C before and the topic below was mine.

I changed my CCS to Version: 8.1.0.00011 and my i²c communication does not work anymore.
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up for GPIO32 (SDAA)
GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0; // Enable pull-up for GPIO33 (SCLA)
GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // Asynch input GPIO32 (SDAA)
GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3; // Asynch input GPIO33 (SCLA)
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; // Configure GPIO32 for SDAA operation
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1; // Configure GPIO33 for SCLA operation
EDIS;
void I2CA_Init(void)
{
I2caRegs.I2CMDR.all = 0x0000;
// Initialize I2C
I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code
// I2CCLK = SYSCLK/(I2CPSC+1)
I2caRegs.I2CPSC.all = 8; //6 // 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; // 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;
}
Uint16 ReadEeprom(Uint16 e2promaddress)
{
Uint16 addresslow;
Uint16 addresshigh;
I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C
while (I2caRegs.I2CSTR.bit.BB == 1); // busy loop
I2caRegs.I2CSTR.bit.SCD = 1; // Clear the SCD bit (stop condition bit)
while(I2caRegs.I2CMDR.bit.STP == 1); // stop bit loop
addresshigh = e2promaddress>>8;
addresslow = e2promaddress;
I2caRegs.I2CSAR = 0x0050;
while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CMDR.all = 0x2620; // start, no stop bit, master, tx, reset I2C
I2caRegs.I2CCNT = 0x0002;
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
while(!I2caRegs.I2CSTR.bit.ARDY); // all ready?
I2caRegs.I2CMDR.all = 0x2C20; // start, stop bit when CNT =0, master, rx, reset I2C
I2caRegs.I2CCNT = 1;
if(I2caRegs.I2CSTR.bit.NACK == 1)
{
I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT; // 0x0002
}
I2caRegs.I2CMDR.bit.STP = 1; // stop bit when CNT=0
while(!I2caRegs.I2CSTR.bit.SCD); // stop bit detected?
dataReadSample[e2promaddress] = I2caRegs.I2CDRR; // read data
DELAY_US(100);
return(dataReadSample[e2promaddress]);
}
void WriteEeprom(Uint16 e2promaddress, Uint16 data)
{
Uint16 addresslow;
Uint16 addresshigh;
I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C
addresshigh = (e2promaddress>>8)&0x00FF;
addresslow = e2promaddress&0x00FF;
I2caRegs.I2CSAR = 0x0050; // EEPROM control bits + address (A0-A2). for 24LC256, 0 1 0 1 0 A0 A1 A2
while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CCNT = 3 ;
I2caRegs.I2CMDR.all = 0x6E20; //start, stop, no rm, reset i2c
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
//I2caRegs.I2CDXR = (data >> 8) & 0x00FF; // high byte data
I2caRegs.I2CDXR = data; // low byte data
dataWriteSample[e2promaddress] = I2caRegs.I2CDXR;
I2caRegs.I2CMDR.bit.STP = 1; // stop bit when CNT=0
while(!I2caRegs.I2CSTR.bit.SCD); // stop bit detected?
DELAY_US(5000); // 5ms = write cycle time of 24LC256 - based on datasheet 24LC256
return;
}
When I try to read or write, I wait here.
I2caRegs.I2CMDR.bit.STP = 1; // stop bit when CNT=0
while(!I2caRegs.I2CSTR.bit.SCD); // stop bit detected?
My hardware seems ok. When stop bit is detected, SCLA becomes 0V and SDAA stays as 3.3V on the oscilloscope. The codes worked before. What should the problem be?
