http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/59371.aspx
Hello guy I am trying to Setup a test communication using I2C communication protocoal. I have came across the simlar probelm discribed in the above Forum that my code is stuck in the master busy Loop. The proposed solution does not works for me as I am using PD6 and PD7 as SDA and SCL. so GPIOPinUnlock() fix doesnot look useful. I a, using processor F28M36P63C2T.
Here is my code I have posted my main program with the Definition of the write command along with the initialization of the I2C SDA and SCL;
int main()
{ SetupPeripherals::init();
TimerUnit timerUnit;
#if defined(TEST_FRAM)
{
char * testString = "Simple Test for SD card.";
I2C::writeData(0, (u8_t*)testString, 1);
Kh=1;
char recvString[10];
I2C::readData(0, (u8_t*)recvString, 10);
if( recvString[0] != testString[0] ) {
DEBUG_PRINT("W/R FRAM failed.\n");
}
}
I2C.cpp
bool I2C::writeData(u16_t offset, u8_t* data, int dataLen) {
#if 1
// Address
I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, I2C_SLAVE_ADDRESS, false);
I2CMasterDataPut(I2C1_MASTER_BASE, offset & 0xff);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C1_MASTER_BASE)) {
}
I2CMasterDataPut(I2C1_MASTER_BASE, (offset >> 8) & 0xff);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C1_MASTER_BASE)) {
}
// Data
for( int i = 0 ; i < dataLen - 1 ; ++i) {
I2CMasterDataPut(I2C1_MASTER_BASE, data[i]);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C1_MASTER_BASE)) {
}
}
I2CMasterDataPut(I2C1_MASTER_BASE, data[dataLen-1]);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C1_MASTER_BASE)) {
}
SetupHW.ccp
void SetupPeripherals::initI2C()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
GPIOPinConfigure(GPIO_PD6_I2C1SDA);
GPIOPinConfigure(GPIO_PD7_I2C1SCL);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
HWREG(I2C1_MASTER_BASE + I2C_O_MCR) |= 0x10; // Master enable
I2CMasterInitExpClk(I2C1_MASTER_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED), true);
I2CSlaveEnable(I2C1_SLAVE_BASE);
I2CSlaveInit(I2C1_SLAVE_BASE, I2C_SLAVE_ADDRESS);
}