6 years, 2 months ago.

MPU6050 on FRDM KL46Z


I have an mpu6050 hooked upto an FRDM KL46Z. I am able to read raw values from it. But whenever i try to use the on board DMP, I am unable to get any output from it. All my connections are correct as I am able to read the raw values.

Has anyone had any success with this?

Appreciate any help!!

1 Answer

6 years, 2 months ago.


The mpu6050 is a tricky device. I'll try to help you out here. I did get the mpu6050 working with the DMP with the KL25Z. Your KL46Z should also work.

You already got the raw values, this is good. Did you try this example program by Shundo Kishi? https://developer.mbed.org/users/syundo0730/code/MPU6050-DMP_sample/file/ec0a08108442/main.cpp

The biggest problem I have is when the I2C connection gets stuck. The mpu6050 will send DMP values for the first few milliseconds, then it stops. As far as I can figure out, the I2C connection gets stuck when the transmit buffer is full. The DMP puts data into the buffer, and your microcontroller must read those values from the buffer. If you don't read the values fast enough, then the buffer overflows and the code breaks (this does not happen with raw values, only with the DMP).

The solution is to slow down the DMP write speed. Alternatively you could try to handle the buffer overflows, but I never figured out how to do that.

Here is what you should try:

1. When you reset your mcu, make sure the mpu6050 is completely powered off. If the mpu6050 is NOT powered down when in DMP mode, the I2C WILL get stuck the next time you try to use it.

2. Decrease the DMP write speed. This is done in line 308 of "mpu6050_6Axis_MotionApps20.h". The line should look like this:


   0x02,   0x16,   0x02,   0x00, 0x09                // D_0_22 inv_set_fifo_rate   
    // This very last 0x09 drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
    // 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
    // DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))

    // It is important to make sure the host processor can keep up with reading and processing
    // the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.

The last number, 0x09, is the DMP write speed. I set it to 0x09 which is the slowest. You can try faster settings if you want. The 100Hz setting works for me when I only read the DMP. If I have more sensors, then I slow it down to 20 or 50Hz.

3. If you have really long wires connecting the mpu6050 to your mcu, you should make the dmp write speed slower. It worked for me with 50cm wires.

4. Are the interrupts working? The "main.cpp" by Shundo Kishi in line 230 only gets data from the DMP if the interrupt is triggered:

   while (!mpuInterrupt && fifoCount < packetSize) {

If you don't have interrupt pins, then comment out this while loop and you will get a tight poll of the DMP which works (but it uses a lot of processor time).

5. Is a motor connected to the circuit? One of my projects had a fairly large motor that causes the mpu6050 to crash. I didn't have proper electrical isolation.

Those are the most common problems I had. I hope this helps. If you still have problems with the mpu6050, feel free to send me more messages. I will help you solve the problem! I may take a couple days to reply.

Mark V

Hi Mark,

Thank you so much. I did try the example that you suggested.

1. The dmp is not working at all. the dmp get initialized but does not transmit data at all.

2. I tested the dmp on an Arduino and it works fine. But i ran into issue number 2 that you had mentioned and I did try slowing it down but it didn't help. So I used a watchdog timer( not the best solution but it worked). That was on the Arduino and not mbed.

3. I had 6" jumper cables. 4. I tried with and without interrupts but no luck at all. 5. no motor

I tried every single thing I could think of but for some reason the dmp just would not work. But an MPU 9150 works on the mbed.

Thanks again for your help.

posted by Mayumi Mohan 29 Jul 2015