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.

RM44L920: I2C Code locked on i2cisStopDetected(i2cREG)

Part Number: RM44L920
Other Parts Discussed in Thread: HALCOGEN

Hi, I have question about I2C Code.

I was looking the example and I've tried to write my own code.

i2cSetSlaveAdd(i2cREG1, Slave_Address); /*Configure address of Slave to talk to*/
i2cSetDirection(i2cREG1, I2C_TRANSMITTER); /*Set direction to Transmitter*/
i2cSetCount(i2cREG1, 1); /*Configure Data count*/
i2cSetMode(i2cREG1, I2C_MASTER); /*Set mode as Master*/
i2cSetStop(i2cREG1); /*Set Stop after programmed Count*/
i2cSetStart(i2cREG1); /*Transmit Start Condition*/
i2cSendByte(i2cREG1, 0x00);

while(i2cIsBusBusy(i2cREG1) == true); /*wait until Bus Busy is cleared*/
while(i2cIsStopDetected(i2cREG1) == 0); /*wait until Stop is detected*/

i2cClearSCD(i2cREG1);
i2cSetSlaveAdd(i2cREG1, Slave_Address); /*Configure address of Slave to talk to*/
i2cSetDirection(i2cREG1, I2C_RECEIVER); /*Set direction to receiver*/

When i started my application, it waited on 'while(i2cIsStopDetected(i2cREG1) == 0);' code.

I followed HALCoGen's example.

What shall i fix for?

Thanks

Anthony

  • Hi Anthony,

    Don't you send STP after sending a byte of data?

  • what is STP?

    when i fixed code like below, it worked.

    but still i don't know the reason it works

    i2cSetSlaveAdd(i2cREG1, Slave_Address); /*Configure address of Slave to talk to*/
    i2cSetDirection(i2cREG1, I2C_TRANSMITTER); /*Set direction to Transmitter*/
    i2cSetCount(i2cREG1, 1); /*Configure Data count*/
    i2cSetStart(i2cREG1);
    while(i2cIsBusBusy(i2cREG1) == true); /*Wait until Bus Busy is cleared*/
    i2cSendByte(i2cREG1, 0x00);
    while((i2cREG1->STR & I2C_ARDY) == false);
    i2cREG1->MDR = I2C_RESET_OUT; // To set the MDR with I"C is out of reset

    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetDirection(i2cREG1, I2C_RECEIVER);
    i2cSetCount(i2cREG1, DATA_COUNT);

    i2cSetStart(i2cREG1);
    i2cSetStop(i2cREG1);
    i2cReceive(i2cREG1, DATA_COUNT, sensTemp); //To receive 2 bytes of Data

    while(i2cIsBusBusy (i2cREG1) == true);

    /* Wait until Stop is detected */
    while(i2cIsStopDetected(i2cREG1) == false);
    /* Clear the Stop condition */
    i2cClearSCD(i2cREG1);

  • Good to know you have make your code works.

    STP is STOP

    Sending one byte of data will not generate STOP automatically. 

    i2cSendByte(i2cREG1, 0x00);
    while((i2cREG1->STR & I2C_ARDY) == false); --> You can check BB here instead.

  • On HALCoGen Help(example_i2cSlave_TX_RX.c), don't send STP.

    Then, If i wanna make my code to example, should i use i2cSend instead of iwcSendByte?

  • The STOP condition is automatically generated when the counter reaches zero.