unable to use MMA8451 on KL46Z with I2C_LDD

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

unable to use MMA8451 on KL46Z with I2C_LDD

906 Views
thomas_l
Contributor I

First post in the forum so hopefully the question description is not too hard to understand.

 

I have been trying to interface with MMA8451 that is built-in to the KL46Z board. I used I2C_LDD as the component to communicate with the accelerometer.

 

There are two functions I've been using to Initialize and read data from the built-in MMA8451. Both functions came from the Sensor Fusion project from Freescale.

 

After fruitlessly working with the code for more than a week, I've come here for help.

 

There have been a few problems that I've encountered but the one I am having right now is that in the MasterSendBlock function, the bus is always busy even when I try to put the accelerometer in standby (which is the first ever communication with the MMA before all other configurations).

 

More specifically: I2C_PDD_GetBusStatus(I2C0_BASE_PTR) == I2C_PDD_BUS_BUSY   always return TRUE.

 

Even more frustrating is that the code works sometimes but not always. The same exact code worked on this board last night (thisAccel structure which contains the raw readings of acclerometer had changing values if I let the program run), but when I tried it this morning, it stopped working.

 

Please help.

Original Attachment has been moved to: SENS-ver1.rar

2 Replies

627 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Tingkai Liu:

I am not familiar with that application to know what values to expect, but I tried the project in a FRDM-KL46Z and it seems to be working. Both sets of values (iGp/ints and fGp/floats) change with each reading when I run the project. For the float values please notice you have to change the format in KDS expressions view to "Default" for each fGp field (Right click -> Number Format -> Default). Otherwise, before doing this I was just seeing 0's for the 3 values. See this picture:

pastedImage_0.png

As recommendation do not step through the I2C code, use step over or run with breakpoints instead.

If it is still failing then it is always useful to check the SDA/SCL lines with an oscilloscope or logic analyzer to see what is going on.

Regards!

Jorge Gonzalez

627 Views
thomas_l
Contributor I

Hey Jorge,

Thank you for the reply! The tip regarding fGp was really helpful.

I don't think there is anything wrong with the code since it has been checked and re-checked many times by a few of my friends and myself.

Fortunately, it is now working without me changing any settings. Hopefully it'll stay this way!

Tingkai