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.

I2C loopback mode

 I want to perform I2C loopback test in my standalone application.But I dont know its flow for performing it.

Do I have followed polling FIFO method.But I am not getting loopback performed.

My code flow:

->disable the I2C module

->configure I2C_SYSTEST register for loopback mode

->add thresold value in Rx FIFO & tx FIFO

->enable the module (set I2C_EN bit )

-> XRDY bit of I2C_STAT register...if 1 then write to I2C_DATA register for txthresold+1 times

->poll RRDY bit of I2C_STAT register...If 1 read the I2C_data register...

Please let me know if I forget anything to be done in my code.

  • Hi Ketankumar Patel,

         Seems to me like you are doing all right, but if you really were doing everything correctly you were working, what crosses my mind is to watch for

    I2Ci.I2C_STAT[12] BB bit = 0

         You should not start your sequence if it is set, and wait until is cleared. But I admit this is an obvious you probably doing this right now. other thing that I can think of is check for FREE bite,

    I2Ci.I2C_SYSTEST[14] FREE = 1

    When is cleared, If Master mode, it stops after completion of the ongoing bit transfer. In slave mode, it stops during the phase transfer when 1 byte is completely transmitted/received.

    When set, free running mode.

    Regards,

    Rodrigo

  • It is still not working.Please let me know steps to perform loopback mode of I2C.

    Below is my code:

    ===============================

    //intialize i2c controller

    i2c_init(0x40,100000); //(address, speed)

    //disabling module & putting it into F/S mode=default mode
    writew(I2C_CON_EN,&i2c_base->con);  

    // free running mode + loopback test mode +enabling system test mode
    writew(0xF000,&i2c_base->systest);

    //enabling module
    writew(I2C_CON_EN,&i2c_base->con);

    //waiting for bus to free

    while(I2C_STAT_BB & readw(&i2c_base->stat));

    //transmit

    while(!(readw(&i2c_base->stat) & I2C_STAT_XRDY));
    printf("\nTransmit ready\n");
    writew(0x55,&i2c_base->data); //writing only one byte as TXTHRS=0 default

    ///receive
    while(!(readw(&i2c_base->stat) & I2C_STAT_RRDY));
    printf("\nReceiver ready\n");
    data_rx=readw(&i2c_base->data); //read data register
    printf("\nReceived data=%d\n",data_rx);

    =================================================

    I can poll both RRDY & XRDY but received data is always 0.& thats the problem.Let me know if I doing wrong or missing.

  • Hi Ketankumar:

       you may want to take a look at the link bellow, it have some interesting tool you may find usefull

    http://elinux.org/Board_Bringup_Utilities


    Regards,

    Rodrigo

  • Hi Ketankumar:

          I insist on you are missing, the prescaler and SCL con figurations,

    //disabling module & putting it into F/S mode=default mode
    writew(I2C_CON_EN,&i2c_base->con);  

    // free running mode + loopback test mode +enabling system test mode
    writew(0xF000,&i2c_base->systest);

    // prescaler settings (I2Ci.I2C_PSC)
    writew(0x????,&i2c_base->psc);

    // Low and hight time values (I2Ci.I2C_SCLL and I2Ci.I2C_SCLH)
    writew(0x????,&i2c_base->scll);
    writew(0x????,&i2c_base->sclh);

    // setup required fifo size - 1. RTRSH and XTRSH (I2Ci.I2C_BUF)
    writew(0x????,&i2c_base->buff);

    //enabling module
    writew(I2C_CON_EN,&i2c_base->con);

    Regards,

    Rodrigo

  • Hi, 

    Its working now.Thanks Rodrigo.

    thanks,

    Ketan Patel