This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

lm4f132h5qd i2c problem

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);

  • swati arora said:
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    You've used an older Stellaris function - improper for your (and our) LX4F and newer, rebrand devices.  MCU manual and SW-DRL-UG9453 reveal the updated requirement as, "GPIOPinTypeI2CSCL()" - for the "SCL" pin.  (You may use your version for the "SDA" pin - but a 2nd call (as just illustrated) is required. 

    And - see no inclusion of GPIOPinConfigure() for each I2C pin - which is "normal/customary."  (may be "escaped" in this usage - your MCU - those specific pins - due to "default" behavior.   But it is poor practice to "rely" upon such defaults - and will "bite you" in the future when you "copy/paste" your code to another I2C port - or MCU...)

    Have not reviewed your listing further - many "miss" the "7 bit address" requirement of the "slave address" parameter.  The 8th bit (I2C's R/W) is auto-filled via "SlaveAddrSet()" true/false.  Check this.

    And - external pull-up Rs - each I2C line - save hours of frustration - despite their size/cost... (i.e. 06-03 and 0.10 USD)  Use them...

  • thank you for the answer but i had checked that,it was mistake.now it is working fine.

    but there is a small problem my rtc is not getting increamented after delay..????

  • swati arora said:
    but there is a small problem

    Problems always seem "small" - and a too rushed/brief description forces extra effort upon your "helpers."

    Somehow, "now it is working fine" - quickly followed by, "small problem" - seems a contradiction...

  • hello,

    you were right  Problems always seem "small" - and a too rushed/brief description forces extra effort upon your "helpers."

    now i have another problem regarding this

    i am using M41T60 RTC ic here i am clearing the bit ST as written in the datasheet .

    but i am not getting correct value increamented 

    i always get 2 value increamented even if i would double the delay or not everytime i put delay rtc only increamented by 2. whether the delay is of 2 second or 4 second or 6 secong no matters...

    please help me out how to run rtc correctly???

  • Feel you pain - but this is vendor's forum - and your issue has moved from your past I2C problem (which was quickly diagnosed/cured - yet somehow remains unverified) now to an operational, connection or understanding issue - revolving around some other vendor's IC.  (most here do not have that data - nor interest in the time/effort to acquire it - and then review)  Cannot you find a simpler RTC chip - and use it?  And - of course the MCU may have some RTC capability of its own.

    Is this forum the proper place to solve, "each/every problem encountered - with other vendor's devices?"  If yes - how, when, where - and by whom - is any limitation to be applied - ever? 

    This "extra-MCU" practice - unfortunately encouraged by the ramping "launch-pad accessory talk" being "dumped" here - dilutes the MCU focus of this forum - which cannot be good.  (this reporter would much prefer a launch-pad accessory forum - dedicated to such issues - as a more managed alternative)  (i.e. it was important enough to "divorce" rebrand forum from Stellaris - yet now launchpad accessories near daily "infiltrate" this space - and too often deal only tangentially w/MCU issues - frequently focusing upon accessory "quirks!"   Predictably results in more relevant MCU-centric issues lingering or being detail restricted - due to this expanded focus/tech staff workload ...)