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.

CCS/TM4C123GH6PM: MPU6050Callback state machine - IDLE state

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello, 

I'm trying to analyze the MPU6050Callback code in mpu6050.c from sensorlib.

The state machine in the code is neatly written with a "case" statement describing what happens in every state.

Only one state isn't described with a "case" statement: MPU6050_STATE_IDLE

Why is the idle case an exception ?

  • The IDLE state will cause the code to execute the "default:" case, which is the same as the "MPU6050_STATE_READ" case. Since in this case the variable ui8State gets set to "MPU6050_STATE_IDLE", nothing changes.

    I am concerned why you are focusing on the static call back function used in mpu6050.c. Are you writing your own support library functions for the mpu6050 instead of using the function in mpu6050.c? Have you seen the example in section 15.3 of the TivaWare Sensor Library User's Guide (www.ti.com/.../spmu371d.pdf In this example, a very simple user call back function is used that simply sets a volatile variable when the MPU6050 has completed the requested task.
  • I am concerned why you are focusing on the static call back function used in mpu6050.c. Are you writing your own support library functions for the mpu6050 instead of using the function in mpu6050.c? 


    Not at all.

    I was exploring how the static MPU6050Callback from mpu6050.c works because I wanted to simply copy it, rename it to "USER_MPU6050Callback" without any further changes and use it as my callback function...

    The original MPU6050Callback has a fully featured state machine while the one in the example doesn't...

    1. Is there a good reason why I should use the one in the example instead of the original one ?

    2. If there's - where does the original MPU6050Callback see use anyway ?

  • Can anyone shed some light on this ?
  • I am not sure I can shed light on this because I am not sure what you are trying to accomplish. The static callback function is used by the routines within the file mpu6050.c to transition from state to state as the TM4C reads and writes the MPU6050 with I2C commands. The user callback routine is an optional function to indicate the status of the previous operation or to execute an error routine. If a callback is not needed, just use a NULL pointer instead. In my mind the two are completely separate. What is it that you want to accomplish in the user callback routine?
  • Thanks.
    This made it clear.

    I didn't notice that the "MPU6050Callback" is used inside the functions (MPU6050Init , MPU6050Read , MPU6050Write, etc...).
    I was under the impression that it's passed as an argument to these functions - which isn't the case.