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.

TMS320F28069M: I2C read data displacement

Part Number: TMS320F28069M

Tool/software:

Here we use the instaspin solution to rotate the motor, and then add I2C communication to communicate with the VL53L4CD sensor. There is a problem with reading data displacement.

Follow the steps below to send and receive

step1.  WRITE Addr: 0x29 ControlData: 01 0F

step2.  READ   Addr: 0x29 ControlData: EB AA

step3.  WRITE Addr: 0x29 ControlData: 00 E5

step4.  READ   Addr: 0x29 ControlData: 03 00

step5.  WRITE Addr: 0x29 ControlData: 00 2D 00

According to my program definition, the value of EB AA should be returned to ReadData[0], and the value of 03 00 should be returned to ReadData[1]

But the result is as follows

ReadData[0] = 03 00

ReadData[1] = EB AA

有什麼問題嗎?

  • Hi ChiHsiang,

    Thanks for reaching out on E2E forums. Your hardware configurations looks to be correct since you are seeing the expected values and verifying from the scope. I see that on your scope shot, you have READ of EBAA 0300 EBAA 0300 in that order. I wonder if there is an issue in the code which causes the first instance of READ EBAA (index 2) to be discarded or unused. Then what you are actually seeing in the ReadData buffer is Index 4 and Index 7.

    Is there a way to send data that is not repeated from the target device?

    Is your code polling or interrupt based? Can you check if your FIFO is overflowing? Are you ever discarding any data from the read FIFO?

    Regards,

    Peter

  • Hi Peter


    Thanks for your reply, I use polling to communicate with the sensor, and I2C to query the sensor's ID and FW version. It seems that the sensor is giving me the correct information.(No missed responses)


    I have confirmed in my program that only the area shown in the screenshot uses ReadData[0] and ReadData[1]. I use them exclusively to receive the values of the sensor response, and there is no situation where ReadData[0] and Read[1] are discarded.


    How do I know if FIFO is overflowing? Is it by checking if the i2c is busy? I only send the next data after the previous data is sent (bit.STP == 0)


    I found a way to prevent the received data from shifting. After the reception starts, add a waiting time of 200 counts. How do I know this time? (I think the data is not ready yet, so this strange phenomenon occurs.) Because the query and reading actions must be performed while the motor is running, the addition of waiting time will risk causing the motor control to be unsmooth. I hope to minimize this delay.


    Regards,
    CHIHSIANG

  • Hi Peter

    I just found that if I remove the 56 pins used for testing, the original 200 counts will be insufficient and need to be increased to 400 counts. What is the reason?

    Regards,

    CHIHSIANG

  • Hi ChiHsiang,

    How do I know if FIFO is overflowing? Is it by checking if the i2c is busy? I only send the next data after the previous data is sent (bit.STP == 0)

    Since you are polling then that means that you should be reading the data as it comes end as you send the data. So you can try to configure a FIFO interrupt, set it to a specific FIFO level that exceeds the current number of receive data you are reading. If the FIFO interrupt gets triggered that tells you the FIFO is receiving more data than you are expecting. I think this is likely not the case but can be good to have for debugging.

    Because the query and reading actions must be performed while the motor is running, the addition of waiting time will risk causing the motor control to be unsmooth. I hope to minimize this delay.

    It is definitely not optimal to affect the control loop. For your purposes, how frequently do you need to read the sensor data, and and is the sensor information being used in the motor control loop or is it for other purpose? You may be able to delay the reading of the data to the next polling cycle if the device takes too long to respond. You can use the FIFO to store the data from the previous write operation

    Regards,

    Peter

  • Hi Peter

    I hope to have a reading speed of more than 250hz. I will modify it to read the data in the following polling cycle.

    I currently clear the FIFO data before reading to ensure that I don't get wrong information.

    Regards.

    ChiHsiang

  • Hi Peter

    Here I refer to your advice and read the data in the next polling cycle. I can successfully read the value transmitted by the ToF sensor. Thank you.

    Regards,

    ChiHsiang