From 46e1a3d46350622a9d57ab6252bd870ebd0d5f26 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 8 Dec 2023 13:12:07 -0600 Subject: [PATCH 1/3] set FIFO rate, MPU addr in dmpInitialize --- src/MPU6050.h | 2 +- src/MPU6050_6Axis_MotionApps20.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MPU6050.h b/src/MPU6050.h index aa05833..762b495 100644 --- a/src/MPU6050.h +++ b/src/MPU6050.h @@ -972,7 +972,7 @@ class MPU6050 { // special methods for MotionApps 2.0 implementation #ifdef MPU6050_INCLUDE_DMP_MOTIONAPPS20 - uint8_t dmpInitialize(); + uint8_t dmpInitialize(uint8_t rateDivisor, uint8_t mpuAddr); bool dmpPacketAvailable(); uint8_t dmpSetFIFORate(uint8_t fifoRate); diff --git a/src/MPU6050_6Axis_MotionApps20.h b/src/MPU6050_6Axis_MotionApps20.h index b8fed6c..012a607 100644 --- a/src/MPU6050_6Axis_MotionApps20.h +++ b/src/MPU6050_6Axis_MotionApps20.h @@ -275,7 +275,7 @@ const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = { #endif // I Simplified this: -uint8_t MPU6050::dmpInitialize() { +uint8_t MPU6050::dmpInitialize(uint8_t rateDivisor = MPU6050_DMP_FIFO_RATE_DIVISOR, uint8_t mpuAddr = 0x68) { // reset device DEBUG_PRINTLN(F("\n\nResetting MPU6050...")); reset(); @@ -309,8 +309,8 @@ uint8_t MPU6050::dmpInitialize() { setSlaveAddress(0, 0x7F); DEBUG_PRINTLN(F("Disabling I2C Master mode...")); setI2CMasterModeEnabled(false); - DEBUG_PRINTLN(F("Setting slave 0 address to 0x68 (self)...")); - setSlaveAddress(0, 0x68); + DEBUG_PRINTLN(F("Setting slave 0 address to self...")); + setSlaveAddress(0, mpuAddr); DEBUG_PRINTLN(F("Resetting I2C Master control...")); resetI2CMaster(); delay(20); @@ -340,7 +340,7 @@ uint8_t MPU6050::dmpInitialize() { DEBUG_PRINTLN(F("Success! DMP code written and verified.")); // Set the FIFO Rate Divisor int the DMP Firmware Memory - unsigned char dmpUpdate[] = {0x00, MPU6050_DMP_FIFO_RATE_DIVISOR}; + unsigned char dmpUpdate[] = {0x00, rateDivisor}; writeMemoryBlock(dmpUpdate, 0x02, 0x02, 0x16); // Lets write the dmpUpdate data to the Firmware image, we have 2 bytes to write in bank 0x02 with the Offset 0x16 //write start address MSB into register From bd8f451a6751195b1df32561ac38db64f738f041 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 13 Dec 2023 12:23:34 -0600 Subject: [PATCH 2/3] add dmpInitialize changes for PU6050_6Axis_MotionApps_V6_12.h --- src/MPU6050_6Axis_MotionApps_V6_12.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MPU6050_6Axis_MotionApps_V6_12.h b/src/MPU6050_6Axis_MotionApps_V6_12.h index f8c0144..2472cb3 100644 --- a/src/MPU6050_6Axis_MotionApps_V6_12.h +++ b/src/MPU6050_6Axis_MotionApps_V6_12.h @@ -351,7 +351,7 @@ const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = { // this is the most basic initialization I can create. with the intent that we access the register bytes as few times as needed to get the job done. // for detailed descriptins of all registers and there purpose google "MPU-6000/MPU-6050 Register Map and Descriptions" -uint8_t MPU6050::dmpInitialize() { // Lets get it over with fast Write everything once and set it up necely +uint8_t MPU6050::dmpInitialize(uint8_t rateDivisor = MPU6050_DMP_FIFO_RATE_DIVISOR, uint8_t mpuAddr = 0x68) { // Lets get it over with fast Write everything once and set it up necely uint8_t val; uint16_t ival; // Reset procedure per instructions in the "MPU-6000/MPU-6050 Register Map and Descriptions" page 41 From 2a9b931ad23b715a504db28574bea9d9bfdf4222 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 13 Dec 2023 12:36:02 -0600 Subject: [PATCH 3/3] use rateDivisor parameter in MotionApps_V6_12.h dmpInitialize --- src/MPU6050_6Axis_MotionApps_V6_12.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MPU6050_6Axis_MotionApps_V6_12.h b/src/MPU6050_6Axis_MotionApps_V6_12.h index 2472cb3..2190722 100644 --- a/src/MPU6050_6Axis_MotionApps_V6_12.h +++ b/src/MPU6050_6Axis_MotionApps_V6_12.h @@ -351,7 +351,7 @@ const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = { // this is the most basic initialization I can create. with the intent that we access the register bytes as few times as needed to get the job done. // for detailed descriptins of all registers and there purpose google "MPU-6000/MPU-6050 Register Map and Descriptions" -uint8_t MPU6050::dmpInitialize(uint8_t rateDivisor = MPU6050_DMP_FIFO_RATE_DIVISOR, uint8_t mpuAddr = 0x68) { // Lets get it over with fast Write everything once and set it up necely +uint8_t MPU6050::dmpInitialize(uint8_t rateDivisor = 0x04, uint8_t mpuAddr = 0x68) { // Lets get it over with fast Write everything once and set it up necely uint8_t val; uint16_t ival; // Reset procedure per instructions in the "MPU-6000/MPU-6050 Register Map and Descriptions" page 41 @@ -365,7 +365,7 @@ uint8_t MPU6050::dmpInitialize(uint8_t rateDivisor = MPU6050_DMP_FIFO_RATE_DIVIS I2Cdev::writeBytes(devAddr,0x1C, 1, &(val = 0x00)); // 0000 0000 ACCEL_CONFIG: 0 = Accel Full Scale Select: 2g I2Cdev::writeBytes(devAddr,0x37, 1, &(val = 0x80)); // 1001 0000 INT_PIN_CFG: ACTL The logic level for int pin is active low. and interrupt status bits are cleared on any read I2Cdev::writeBytes(devAddr,0x6B, 1, &(val = 0x01)); // 0000 0001 PWR_MGMT_1: Clock Source Select PLL_X_gyro - I2Cdev::writeBytes(devAddr,0x19, 1, &(val = 0x04)); // 0000 0100 SMPLRT_DIV: Divides the internal sample rate 400Hz ( Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)) + I2Cdev::writeBytes(devAddr,0x19, 1, &(val = rateDivisor)); // 0000 0100 SMPLRT_DIV: Divides the internal sample rate 400Hz ( Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)) I2Cdev::writeBytes(devAddr,0x1A, 1, &(val = 0x01)); // 0000 0001 CONFIG: Digital Low Pass Filter (DLPF) Configuration 188HZ //Im betting this will be the beat if (!writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) return 1; // Loads the DMP image into the MPU6050 Memory // Should Never Fail I2Cdev::writeWords(devAddr, 0x70, 1, &(ival = 0x0400)); // DMP Program Start Address