This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to write DMP code to MPU6050 memory banks via NRF52832 with MBED ?

Hi,

I'm having issues with my MPU6050 sensor. I'm trying to get yaw, pitch and roll raw sensor values from MPU6050 sensor using DMP on MBED platform but without success.

Things I already tried:

  • Getting raw sensor values using DMP with arudino by following this tutorial Arduino. It worked flawlessly.

  • I tried following this NRF52832 + Arduino tutorial to use the same arduino code but on NRF52832 and again everything worked.

  • I am trying to use MBED example of a ported arduino code to get values but without success. I am pretty sure that all pins are wires are connected properly and I tried many more MBED examples that use DMP to get values and each and everytime I get this message:

    ERROR! DMP code verification failed. DMP Initialization failed (code 1)

I am not that much familiar with MPU6050 registers and their purpose but I went line by line in both arduino and mbed example to see if something is missing. I found out that arduino example manages to write DMP code but mbed example fails.

This is part in MPU6050.cpp where MBED example fails to properly write DMP code in memory banks:

 I2Cdev::writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer);
    // verify data if needed
    if (verify && verifyBuffer) {
        setMemoryBank(bank);
        setMemoryStartAddress(address);
        I2Cdev::readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer);
        if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) {
            /*Serial.print("Block write verification error, bank ");
            Serial.print(bank, DEC);
            Serial.print(", address ");
            Serial.print(address, DEC);
            Serial.print("!\nExpected:");
            for (j = 0; j < chunkSize; j++) {
                Serial.print(" 0x");
                if (progBuffer[j] < 16) Serial.print("0");
                Serial.print(progBuffer[j], HEX);
            }
            Serial.print("\nReceived:");
            for (uint8_t j = 0; j < chunkSize; j++) {
                Serial.print(" 0x");
                if (verifyBuffer[i + j] < 16) Serial.print("0");
                Serial.print(verifyBuffer[i + j], HEX);
            }
            Serial.print("\n");*/
            free(verifyBuffer);
            if (useProgMem) free(progBuffer);
            return false; // uh oh.
        }
    }

First it tries to write first 16 bytes block and then reads it to verify if everything is OK.

Output is something like this:

Block write verification error, bank 0, address 0!
Expected: 0xfb 0x00 0x00 0x3e 0x00 0x0b 0x00 0x36 0x00 0x01 0x00 0x02 0x00 0x03 0x00 0x00
Received: 0x00 0x00 0x00 0x00 0x00 0x00 0x68 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

It seems that MBED either fails to write or read MPU6050_RA_MEM_R_W register. I think that I2C library ported for MBED is fine because I use it in other projects to read/write arbitrary buffer to other registers. I already tried with different chunk sizes and different i2c frequency. The other thing is that Arduino example receives different buffer when reading this register but mbed always reads the one above ("Received"). I tried everything and double check each address and register but everything is same. I am really stuck here for 2 weeks.

I hope someone here can help me.

Thanks Osman

  • Hi Osman,

    We mainly support the Nordic SDK, so if you want full support from this forum I would suggest you try using the SDK instead of mbed if it is possible. Mbed has its own forum if you have not tried to post your question there.

    That said you could try to connect a logic analyzer or oscilloscope to the TWI (i2c) lines to see if the correct data is transfered. I don't know if you can do debugging with your code, but you can at least try to log when you do the TWI transactions and see if this is the same you get with the Arduino code.

    I am sorry, but it is kind of hard to help you with this question. I have tried DMP code using the SDK and nRF52 and it has worked for me. I am not able to share the code, but it was based on the I2Cdev library.

Related