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