Hello,
I posted about my issues with the C6713 DSK's I2C module a while back (http://e2e.ti.com/support/dsp/tms320c6000_high_performance_dsps/f/115/p/73053/268178.aspx#268178), and while I've come a long way since then, I'm still having some serious issues. The program below does the following:
1) Generate START condition.
2) Write a byte of data to a PIC slave.
3) Overwrite I2CMDR for master receiver mode while again generating START condition.
4) Read a byte of data from the PIC slave.
while(1)
{
// Open I2C device 0 and reset I2C module:
hI2c=I2C_open(I2C_DEV0,I2C_OPEN_RESET);
// Configure I2C device:
I2C_RSETH(hI2c,I2CCLKH,35);
I2C_RSETH(hI2c,I2CCLKL,35);
I2C_RSETH(hI2c,I2CMDR,0x0600);
I2C_RSETH(hI2c,I2CCNT,1);
I2C_RSETH(hI2c,I2CSAR,0x24);
I2C_RSETH(hI2c,I2COAR,0);
I2C_RSETH(hI2c,I2CIER,0);
I2C_RSETH(hI2c,I2CPSC,13);
I2C_RSETH(hI2c,I2CMDR,0x0620); // Exit reset mode.
while(I2C_FGETH(hI2c,I2CSTR,BB)); // Wait for bus to be free.
I2C_RSETH(hI2c,I2CMDR,0x2620); // Set START bit.
while(!I2C_FGETH(hI2c,I2CSTR,ICXRDY)); // Wait until ready to transmit.
I2C_writeByte(hI2c,0x01); // Request "gain" value from PIC.
//while(!I2C_FGETH(hI2c,I2CSTR,ARDY)); // Wait until stop bit is generated.
I2C_RSETH(hI2c,I2CCNT,1); // Set counter to 1 byte.
I2C_RSETH(hI2c,I2CMDR,0x2C20); // Switch to receive mode, and set STT and STP.
while(!I2C_FGETH(hI2c,I2CSTR,ICRRDY)); // Wait until ready to receive.
distortion=I2C_readByte(hI2c); // Read byte.
//while(I2C_FGETH(hI2c,I2CMDR,MST)); // Wait to exit master mode.
I2C_close(hI2c);
printf("end\n");
}
If you'll notice, two of my "while" lines are commented out. I'm quite sure that, after writing, I need to wait for ARDY to go high due to I2CCNT decrementing to 0. My first issue is that I2CCNT never seems to decrement, but instead stays at 1. The other commented line (waiting to exit master mode) is also an issue because again, I2CCNT never decrements, and thus the I2C module never generates the STOP and never exits master mode to signify the end of the transmission. The code does work as shown above, but it only writes and reads once rather than looping as it's supposed to. I can only assume that this issue has something to do with those two lines and/or with I2CCNT.
So, to summarize, my questions are as follows: Why isn't I2CCNT decrementing? Is this keeping the I2C process from looping, or is there some other reason? If the latter, does anyone have suggestions as to what might be wrong?
Any help would be very much appreciated. I've been working on this for over a month now, and I'm completely frustrated. Thanks!
Danielle