hello
i am using lm4f132h5qd,here my i2c0 is communicating with a RTC M41T60.
but when i writing a value to the rtc it always get stucked with i2c master busy.
my codes are:
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);
void RTCWrite(unsigned char RTC_slaveaddr, unsigned char MSBaddr, unsigned char data )
{
unsigned int i;
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, RTC_slaveaddr, false);
I2CMasterDataPut(I2C0_MASTER_BASE, MSBaddr);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_MASTER_BASE));
I2CMasterDataPut(I2C0_MASTER_BASE,data);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_MASTER_BASE));
for(i=0;i<20000;i++);
}
unsigned char ReadRTC(unsigned char RTC_slaveaddr, unsigned char MSBaddr)
{
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, RTC_slaveaddr, false);
I2CMasterDataPut(I2C0_MASTER_BASE, MSBaddr); //cmd to write to config register
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_MASTER_BASE));
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, RTC_slaveaddr, true);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusy(I2C0_MASTER_BASE));
return(I2CMasterDataGet(I2C0_MASTER_BASE));
}
RTCWrite(0x68,0,0x80);
for(i=0;i<60000;i++);
for(i=0;i<60000;i++);
for(i=0;i<60000;i++);
get = ReadRTC(0x68,0);