Jump to content
I2Cdevlib Forums

MPU-DMP example code


Recommended Posts

First off, thank you for an awesome library. Running low on space in the atmega328 so streamlining code and came across the following nuances

 

Taken right from the example that comes with the libraries, MPU6050_DMP6.INO i was wondering why?

 

1. During setup, this line occurs:

 

 mpu.initialize();

 

followed by this line:

 

devStatus = mpu.dmpInitialize();

 

Which resets the device and changes any configs set by the the first initialize(). The first initialize line can be commented out completely and functions the same.

 

Is it req'd at all?

 

2. In the motion_apps.h this line occurs many times and i was wondering why?

 for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
            writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);

 for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
            writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);

The code is exactly the same, in fact deleting the whole section of dmpupdates, resets, enables etc seems to have no effect on operation.

 

Was curious as to why the above statement is repeated exactly with the same data many times.

 

Thanks in advance. I'm just looking to save some compiled code space.

            uint8_t dmpUpdate[16], j;
            uint16_t pos = 0;
            for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
            writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
/*
            for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
            writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
*/
            resetFIFO();

            uint16_t fifoCount = getFIFOCount();
            uint8_t fifoBuffer[128];

            getFIFOBytes(fifoBuffer, fifoCount);
            setFIFOEnabled(true);
            setDMPEnabled(true);
            resetDMP();
/*
			for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
			writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
			for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
			writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
			for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
			writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);

			while ((fifoCount = getFIFOCount()) < 3);  getFIFOBytes(fifoBuffer, fifoCount);

			uint8_t mpuIntStatus = getIntStatus();

			for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
			readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);

			while ((fifoCount = getFIFOCount()) < 3);  getFIFOBytes(fifoBuffer, fifoCount);

			//mpuIntStatus = getIntStatus();
			
			for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
            writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
*/

            //setDMPEnabled(false);

	//$$$$ set to 18 for quaternion only
            dmpPacketSize = 18;

            //resetFIFO();
            //getIntStatus();
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...