AnsweredAssumed Answered

LPI2C Receive error

Question asked by Vasudhevan G on May 5, 2020
Latest reply on Jun 10, 2020 by Vasudhevan G

Hii,

     Board = IMXRT1064 evk

     PCF8563 rtc module interfaced with LPI2C1 master.

     Whenever i am trying to read using LPI2C_MasterReceive call returning 999.

     Code :

    #define LPI2C_MASTER_SLAVE_ADDR_7BIT 0xA2U
    #define LPI2C_MASTER_SLAVE_ADDR_READ 0xA3U
    #define LPI2C_BAUDRATE 100000U
   
    uint8_t deviceAddress = 0x02U;
    uint8_t recv_data;

    LPI2C_MasterGetDefaultConfig(&masterConfig);

    /* Change the default baudrate configuration */
    masterConfig.baudRate_Hz = LPI2C_BAUDRATE;

    /* Initialize the LPI2C master peripheral */
    LPI2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, LPI2C_MASTER_CLOCK_FREQUENCY);

/* Send master blocking data to slave */
    if (kStatus_Success == LPI2C_MasterStart(EXAMPLE_I2C_MASTER, LPI2C_MASTER_SLAVE_ADDR_7BIT, kLPI2C_Write))
    {
        /* Check master tx FIFO empty or not */
        LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
        while (txCount)
        {
            LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
        }
        /* Check communicate with slave successful or not */
        if (LPI2C_MasterGetStatusFlags(EXAMPLE_I2C_MASTER) & kLPI2C_MasterNackDetectFlag)
        {
            return kStatus_LPI2C_Nak;
        }

        reVal = LPI2C_MasterSend(EXAMPLE_I2C_MASTER, &deviceAddress, 1);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

        reVal = LPI2C_MasterRepeatedStart(EXAMPLE_I2C_MASTER, LPI2C_MASTER_SLAVE_ADDR_READ, kLPI2C_Read);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

/*         Check master tx FIFO empty or not
        LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
        while (txCount)
        {
            LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
        }*/


        /* Check communicate with slave successful or not */
        if (LPI2C_MasterGetStatusFlags(EXAMPLE_I2C_MASTER) & kLPI2C_MasterNackDetectFlag)
        {
            return kStatus_LPI2C_Nak;
        }

        reVal = LPI2C_MasterReceive(EXAMPLE_I2C_MASTER, &recv_data, 1);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

        reVal = LPI2C_MasterStop(EXAMPLE_I2C_MASTER);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

How to solve receive error ?

 

Thanks & Regards,

           Vasu

Outcomes