LPI2C_MasterReceive always return with kStatus_LPI2C_FifoError

cancel
Showing results for 
Search instead for 
Did you mean: 

LPI2C_MasterReceive always return with kStatus_LPI2C_FifoError

Jump to solution
181 Views
Contributor II

as from this function mainly copied from the lpi2c polling master example :

int8_t ucReadI2CSlaveLPI2C1( uint8_t ucSlave, uint8_t address,uint8_t ucDataReaded[], uint8_t ucByteToRead)
{
    status_t reVal        = kStatus_Fail;
    size_t txCount        = 0xFFU;
    if (kStatus_Success == LPI2C_MasterStart(((LPI2C_Type *)(LPI2C1_BASE)), ucSlave , kLPI2C_Write))
        {
            /* Check master tx FIFO empty or not */
            LPI2C_MasterGetFifoCounts(((LPI2C_Type *)(LPI2C1_BASE)), NULL, &txCount);
            while (txCount)
            {
                LPI2C_MasterGetFifoCounts(((LPI2C_Type *)(LPI2C1_BASE)), NULL, &txCount);
            }
            /* Check communicate with slave successful or not */
            while (LPI2C_MasterGetStatusFlags(((LPI2C_Type *)(LPI2C1_BASE))) & kLPI2C_MasterNackDetectFlag)
            {
            }

            reVal = LPI2C_MasterSend(((LPI2C_Type *)(LPI2C1_BASE)), &address, 1);
            if (reVal != kStatus_Success)
            {
                return -1;
            }

            reVal = LPI2C_MasterRepeatedStart(((LPI2C_Type *)(LPI2C1_BASE)), ucSlave, kLPI2C_Read);
            if (reVal != kStatus_Success)
            {
                return -1;
            }

            LPI2C_MasterReceive(((LPI2C_Type *)(LPI2C1_BASE)), &ucDataReaded, ucByteToRead - 1);
            if (reVal != kStatus_Success)
            {
                return -1;
            }

            reVal = LPI2C_MasterStop(((LPI2C_Type *)(LPI2C1_BASE)));
            if (reVal != kStatus_Success)
            {
                return -1;
            }
        }
    return 0xFF;
}

LPI2C_MasterReceive return with kStatus_LPI2C_FifoError and i dont get any data in ucDataReaded but when i look with a logic analyser the transaction with the slave is perfect. What is the problem here?

Labels (1)
Tags (1)
0 Kudos
1 Solution
8 Views
NXP TechSupport
NXP TechSupport

Hope you are well. Could you please attempt to only read one register. The WHO_AM_I register of your slave device. Does the device require a certain pattern in communication before stopping?If so, can you see whether master and slave are following as shown in your device's datasheet. It is possible that you are communicating well and you see that on the logic analyzer, but if there is something expected from the slave like a NAK, then it may show as an error with our drivers. If this is the case, then you will need to make the necessary modifications to fit the needs of your slave.

Please let me know your results.

Best Regards,

Sabina

View solution in original post

0 Kudos
8 Replies
8 Views
Contributor II

its ok now i get data but i still get the errors dont know why.

0 Kudos
8 Views
NXP TechSupport
NXP TechSupport

Hello Claude,

Hope you are doing well.

Could you please attempt to use the example without modifications. It is not possible to tell what the issue may be if you only used the above function. 

Please let me know what your results are with the original example.

Best Regards,

Sabina

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

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

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

0 Kudos
8 Views
Contributor II

The problem is that i get the same problem with the untouched code. The problem is that on the logic analyser the i2c transaction but i dont get the data out of it in the rxbuffer. im using a HTS221 slave ic from ST. I dont think the proble is from the ic cause its an internal fifo error code that i guet what can cause this error?

Annotation 2020-06-10 220317.jpg

0 Kudos
8 Views
Contributor II

OK with further testing i found out that the example work. but how can i implement lpi2c driver in a blank projet i cant just coppy and paste part of the example cause it clearly dont work like that

0 Kudos
8 Views
NXP TechSupport
NXP TechSupport

If you would like to add drivers to a blank project you may do so by selecting the project then right click and scroll down to SDK Manage then select Manage SDK components.

pastedImage_1.png

Here you will have the drivers and middleware options you can add to your blank project.

Once you have selected the drivers you need click ok and rebuild your project. 

If you are implementing sections of the code you have to consider what the example does as a whole. If you only take portions of it, then you have to consider that you might have some portions missing. 

I recommend to work first on the example and make the changes there as you need, then once it is working you can transfer the source file to your blank project.

Best Regards,

Sabina

0 Kudos
8 Views
Contributor II

that's what i did i took the example put it in a function then it stoped working.

0 Kudos
9 Views
NXP TechSupport
NXP TechSupport

Hope you are well. Could you please attempt to only read one register. The WHO_AM_I register of your slave device. Does the device require a certain pattern in communication before stopping?If so, can you see whether master and slave are following as shown in your device's datasheet. It is possible that you are communicating well and you see that on the logic analyzer, but if there is something expected from the slave like a NAK, then it may show as an error with our drivers. If this is the case, then you will need to make the necessary modifications to fit the needs of your slave.

Please let me know your results.

Best Regards,

Sabina

View solution in original post

0 Kudos
8 Views
Contributor II

pastedImage_1.png

0 Kudos