LPI2C Receive error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPI2C Receive error

Jump to solution
5,262 Views
vasudhevan
Contributor V

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

Labels (1)
0 Kudos
Reply
1 Solution
4,971 Views
vasudhevan
Contributor V

Hi Oleg,

      Thank you for your response.

      We missed PCF8563 INT pin pull up resistor after added pull up resistor now working fine.

      Thank you for your support.

Regards,

  Vasu

View solution in original post

0 Kudos
Reply
13 Replies
4,971 Views
oleglavrukhin
Contributor IV

hello, Vasu!

If You still need help:

First of all, you need to determine - this is a software or hardware problem

1) connect PCF8563 to another board (Arduino etc.) to check its performance

2) if your PCF8563 is worked, try to connect it to another I2C port of RT1064 and make a change in code

3) post here or send me to lavrukhin_oe@mail.ru your code and connection diagram PCF8563->RT1064

   and what IDE/SDK You use???

4) about search_I2C(): this procedure scan I2C bus, i.e. polls bus addresses from 1 to 200. if Master get a ACK, it print message in serial port, if Master get Nak, it moves on to the next address.

Good luck

Oleg

0 Kudos
Reply
4,972 Views
vasudhevan
Contributor V

Hi Oleg,

      Thank you for your response.

      We missed PCF8563 INT pin pull up resistor after added pull up resistor now working fine.

      Thank you for your support.

Regards,

  Vasu

0 Kudos
Reply
4,971 Views
oleglavrukhin
Contributor IV

I looking in your initial code. You use 8-bit addresses of PCF8563 (0xA2/0xA3), but You must use 7-bit address 0x51 ( 0xA2>>1). bit 0 in address is set to R/W (0/1) inside I2C driver!

Regards

Oleg

0 Kudos
Reply
4,971 Views
oleglavrukhin
Contributor IV

Hello, Vasu!

I attach my project for search I2C devices and then reading a time from PCF8563 every 1 sec, output to Debug Console.

This project for RT1020 EVK, MCUxpresso 10.3.1, SDK 2.5. 

Used functions BOARD_LPI2C_Init(), BOARD_LPI2C_Send(), BOARD_LPI2C_Receive() (file "board.c")

RTC is connected to LPI2C4, but You can adopted it for RT1060

Pls, replace in "Board.h":

#define BOARD_ACCEL_I2C_BASEADDR LPI2C4 to LPI2C1 ( I see a schematic for RT1060, I2C1 on Arduino connectors J23 and J24 (GPIO_AD_B1_01 is SDA, GPIO_AD_B1_00 is SCL).

and I hope, You did not forget  add a pull-up resistors 4.7 K for SDA and SCL?

I see, on the  EVK  R232 and R234 is 10K, this may not be enough.

If your RTC and oscillator 32768 HZ is connected correctly and worked, you must have a result.

as another way, you may check your code with reading data from FXOS8700CQ COMBO SENSOR (if it populated on your board, on RT1020 it missing).

and (if OK), try it with RTC.

good luck!

Oleg.

PS. write whether you succeeded or not

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

Hi Oleg,

     Thank you for your response.

     Sorry for the late reply.

     search_I2C() -> BOARD_LPI2C_Receive -> LPI2C_MasterReceive returns 902 status code (kStatus_LPI2C_Nak).

     read_rtc() -> BOARD_LPI2C_Receive ->  LPI2C_MasterStart -> LPI2C_CheckForBusyBus return 900 status code(kStatus_LPI2C_Busy).

     Still i am getting issue.

Thanks & Regards,

       Vasu

0 Kudos
Reply
4,971 Views
oleglavrukhin
Contributor IV

Hello, Vasu!

I had the same problem with RT1020 and PCF8563, and I found a solution:

- in MCuxpresso config Tool -> Pins set "Software Input On" to "Enable" (just like "Open Drain" ) for SCL and SDA

after that, I2C works finely, I checked it with BOARD_LPI2C_Receive() and BOARD_LPI2C_Send() functions (SDK_I2C_BASED_COMPONENT_USED=1 in Preprocessor setting) , and with CMSIS-I2C-Driver

Try, hope this help!

Oleg44.jpg

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

Hi Oleg Lavrukhin,

       Thank you for your response.

       Sorry for late reply.

 

MCuxpresso config Tool -> Pins set "Software Input On" to "Enable" (just like "Open Drain" ) for SCL and SDA

    - Already enabled

But still same issue.

Thanks & Regards,

       Vasu

0 Kudos
Reply
4,971 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello ,

Hope you are doing well.

Could you please confirm the value is 999, I am not able to find this value in the return status codes. Status 903 means that there was either a FIFO overrun or under run present. I'd recommend to try the example without making modifications except for your device address to the example you are using and see if you get the same results. Also if possible to check the wave forms to see that the data is being sent out correctly. 

Best Regards,

Sabina

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

Hi Sabina,

       Thank you for your response.

       Instead of 903 wrongly posted 999.

       Imported evkmimxrt1064_lpi2c_polling_b2b_master just modified device address A2.

      

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

        /* subAddress = 0x01, data = g_master_txBuff - write to slave.
          start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
        reVal = LPI2C_MasterSend(EXAMPLE_I2C_MASTER, &deviceAddress, 1);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

/*        reVal = LPI2C_MasterSend(EXAMPLE_I2C_MASTER, g_master_txBuff, LPI2C_DATA_LENGTH);
        if (reVal != kStatus_Success)
        {
            return -1;
        }*/

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

   LPI2C_MasterStop -> LPI2C_MasterWaitForTxReady(base) -> LPI2C_MasterCheckAndClearError(base, status) -> returns 903 status code.

   Due to covid-19 we are not in office not able to take waveform.

Thanks & Regards,

         Vasu

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

Hi Sabina,

        Any update ?

0 Kudos
Reply
4,971 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Vasu,

Hope you are doing well.

I apologize for the delayed response, I have now been able to reproduce this behavior using two boards. When the following section is commented as you have described above I also get the error 903. 

/*        reVal = LPI2C_MasterSend(EXAMPLE_I2C_MASTER, g_master_txBuff, LPI2C_DATA_LENGTH);
        if (reVal != kStatus_Success)
        {
            return -1;
        }*/

However when I uncomment this, the communication is successful. Could you please confirm why you commented these lines?

Best Regards,

Sabina

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

Hi Sabina,

     Thank you for your response.

     Could you please confirm why you commented these lines?

           I am trying to communicate with pcf8563(nxp external rtc).

           While sending A2(write to slave) device address sending fine.

           Read seconds 0x02 register does not return any error.

           LPI2C_MasterStop -> LPI2C_MasterWaitForTxReady(base) -> LPI2C_MasterCheckAndClearError(base, status) -> returns 903 status code.

     RTC read seconds flow :

           start + write device address + reg addr + stop   start + read device address + recive data + stop

     While sending stop returns 903.

     Issue with rtc side (or) mcu side ?

     Can we get any support on pcf8563 nxp rtc ?

Thanks & Regards,

       Vasu

0 Kudos
Reply
4,971 Views
vasudhevan
Contributor V

LPI2C_MasterReceive -> LPI2C_MasterWaitForTxReady(base) -> LPI2C_MasterCheckAndClearError(base, status) returns 903 status code.

How to solve this issue ?

0 Kudos
Reply