InvenSenseInc.Document Number:InvenSense1197Borregas Ave.,Sunnyvale,CA94089 U.SARevision:1.0Tel:+1 (408)988-7339Fax:+1 (408)988-8104Release Date:12/19/2012Website:www.invensense.comEmbeddedMotionDriver5.1.1TutorialAprintedcopyofthisdocumentisNOTUNDERREVISIONCONTROLunless it isdatedandstamped inred inkas,"REVISIONCONTROLLEDCOPY"This information furmished by InvenSense is believed to be accurate and reliable. However, no responsibility is assumed by InvenSense for its use, or forany infringements of patents or other rights of third parties that may result from its use. Specifications are subject to change without notice. InvenSensereserves the right to make changes to this product, including its circuits and software,in order to improve its design and/or performance,without priornotice. InvenSense makes no warranties, neither expressed nor implied, regarding the information and specifications contained in this document.InvenSense assumes no responsibilityforany claims ordamages arising from information contained in this document, or from theuse ofproducts andservices detailed therein. This includes, but is not limited to, claims or damages based on the infringement of patents, copyrights, mask work and/or otherintellectual property rights.Certain intellectual property owned by InvenSense and described in this document is patent protected. No license is granted by implication or otherwiseunder any patent or patent rights of InvenSense.This publication supersedes and replaces all information previously supplied. Trademarks that areregistered trademarks are the property of their respective companies. InvenSense sensors should not be used or sold in the development, storage,production or utilization of any conventional or mass-destructive weapons orfor any other weapons or life threatening applications,as well as in any otherife critical applications such as medical equipment, transportation, aerospace and nuclear instruments, undersea equipment, power plant equipment,disasterpreventionandcrimepreventionequipment.Copyright @2011 InvenSense Corporation
InvenSense Inc. 1197 Borregas Ave., Sunnyvale, CA 94089 U.S.A. Tel: +1 (408) 988-7339 Fax: +1 (408) 988-8104 Website: www.invensense.com Document Number: Revision: 1.0 Release Date: 12/19/2012 Embedded Motion Driver 5.1.1 Tutorial This information furnished by InvenSense is believed to be accurate and reliable. However, no responsibility is assumed by InvenSense for its use, or for any infringements of patents or other rights of third parties that may result from its use. Specifications are subject to change without notice. InvenSense reserves the right to make changes to this product, including its circuits and software, in order to improve its design and/or performance, without prior notice. InvenSense makes no warranties, neither expressed nor implied, regarding the information and specifications contained in this document. InvenSense assumes no responsibility for any claims or damages arising from information contained in this document, or from the use of products and services detailed therein. This includes, but is not limited to, claims or damages based on the infringement of patents, copyrights, mask work and/or other intellectual property rights. Certain intellectual property owned by InvenSense and described in this document is patent protected. No license is granted by implication or otherwise under any patent or patent rights of InvenSense. This publication supersedes and replaces all information previously supplied. Trademarks that are registered trademarks are the property of their respective companies. InvenSense sensors should not be used or sold in the development, storage, production or utilization of any conventional or mass-destructive weapons or for any other weapons or life threatening applications, as well as in any other life critical applications such as medical equipment, transportation, aerospace and nuclear instruments, undersea equipment, power plant equipment, disaster prevention and crime prevention equipment. Copyright ©2011 InvenSense Corporation. A printed copy of this document is NOT UNDER REVISION CONTROL unless it is dated and stamped in red ink as, “REVISION CONTROLLED COPY
Document Number:Revision:1.0InvenSenseEmbeddedMotionDriver5.1.1TutorialReleaseDate:12/19/2012TABLE OF CONTENTS1.REVISIONHISTORY.32.PURPOSE33.REQUIREMENTS.34.INTRODUCTIONTOMOTIONDRIVER..45.OPENINGUPTHEMOTIONDRIVERPROJECTINCODECOMPOSERSTUDIO.56.EXPLAININGMOTIONDRIVERANDTHEFUNCTIONALSPECIFICATIONINMOREDETAIL.....56.1DMP56.2I2CDRIVERTOINTERFACEWITHINVENSENSEIC...66.3GYROSCOPEANDACCELEROMETERSELF-TESTFUNCTIONCALLS.6.4ACCELEROMETERCALIBRATION.6.5GYROSCOPECALIBRATION....86.6...8LOWPOWERACCELEROMETERMOTIONINTERRUPT.6.7ABILITYTOCHANGESENSORODRSOFTHEGYROSCOPEANDACCELEROMETER...86.8ABILITYTOSELECTWHICHDATATOPOPULATEINTHEFIFOUSINGAFUNCTIONCALL...8..7.TESTINGTHEMOTIONDRIVERUSINGTHEMOTIONFITSDKANDPYTHONSCRIPT.....8.GETCOMPASSDATAVIAMOTIONDRIVER.109.COMPASSINTEGRATIONANDCALIBRATION...10...1010.SPIDRIVERIMPLEMENTATION11.APPENDIX.1111.1APPENDIXA.11..1211.2APPENDIXB12.REFERENCES122of12CONFIDENTIAL&PROPRIETARY
Embedded Motion Driver 5.1.1 Tutorial Document Number: Revision: 1.0 Release Date: 12/19/2012 CONFIDENTIAL & PROPRIETARY 2 of 12 TABLE OF CONTENTS 1. REVISION HISTORY . 3 2. PURPOSE . 3 3. REQUIREMENTS . 3 4. INTRODUCTION TO MOTION DRIVER. 4 5. OPENING UP THE MOTION DRIVER PROJECT IN CODE COMPOSER STUDIO . 5 6. EXPLAINING MOTION DRIVER AND THE FUNCTIONAL SPECIFICATION IN MORE DETAIL . 5 6.1 DMP . 5 6.2 I2C DRIVER TO INTERFACE WITH INVENSENSE IC . 6 6.3 GYROSCOPE AND ACCELEROMETER SELF-TEST FUNCTION CALLS . 7 6.4 ACCELEROMETER CALIBRATION . 7 6.5 GYROSCOPE CALIBRATION . 8 6.6 LOW POWER ACCELEROMETER MOTION INTERRUPT . 8 6.7 ABILITY TO CHANGE SENSOR ODRS OF THE GYROSCOPE AND ACCELEROMETER . 8 6.8 ABILITY TO SELECT WHICH DATA TO POPULATE IN THE FIFO USING A FUNCTION CALL . 8 7. TESTING THE MOTION DRIVER USING THE MOTIONFIT SDK AND PYTHON SCRIPT . 8 8. GET COMPASS DATA VIA MOTION DRIVER . 10 9. COMPASS INTEGRATION AND CALIBRATION . 10 10. SPI DRIVER IMPLEMENTATION . 10 11. APPENDIX . 11 11.1 APPENDIX A . 11 11.2 APPENDIX B . 12 12. REFERENCES . 12
DocumentNumber:Revision: 1.0InvenSenseEmbeddedMotionDriver5.1.1TutorialReleaseDate:12/19/20121.Revision HistoryRevisionDescriptionRevisionDate1.012/19/2012Document created2.PurposeMotion Driver is a sensor driver layer that easily configures and leverages the on board Digital MotionProcessor(DMP)capabilitiesofInvenSense's MotionTracking devices.MotionDriveris a subsetof theEmbeddedMotionAppssoftwarethatenableseasierportingtomultipleMCUarchitectures.Thisdocumentillustratesthepractical usageofthe MotionDriverlibrary.The includedtutorial iswrittenfor compatibilitywiththeMSP430embeddedmicrocontrollerfromTl,andassuch,someknowledgeoftheMSP430architectureisrecommended.TheMSP430 isusedasanexampleplatformonly.MotionDrivercanbeportedeasilytoany Mcu.3.Requirements3.1CodeComposerStudio(tocompiletheMSP430exampleonly)3.2MotionDriver sourcefiles3.3MotionFitTMdevelopmentboardorsimilarhardware (forexampleonly)3of12CONFIDENTIAL&PROPRIETARY
Embedded Motion Driver 5.1.1 Tutorial Document Number: Revision: 1.0 Release Date: 12/19/2012 CONFIDENTIAL & PROPRIETARY 3 of 12 1. Revision History Revision Date Revision Description 12/19/2012 1.0 Document created 2. Purpose Motion Driver is a sensor driver layer that easily configures and leverages the on board Digital Motion Processor (DMP) capabilities of InvenSense’s Motion Tracking devices. Motion Driver is a subset of the Embedded MotionApps software that enables easier porting to multiple MCU architectures. This document illustrates the practical usage of the Motion Driver library. The included tutorial is written for compatibility with the MSP430 embedded microcontroller from TI, and as such, some knowledge of the MSP430 architecture is recommended. The MSP430 is used as an example platform only. Motion Driver can be ported easily to any MCU. 3. Requirements 3.1 Code Composer Studio (to compile the MSP430 example only) 3.2 Motion Driver source files 3.3 MotionFit™ development board or similar hardware (for example only)
Document Number:Revision: 1.0InvenSenseEmbeddedMotionDriver5.1.1TutorialReleaseDate:12/19/2012Introductionto Motion Driver4.Motion Driver consists of a set of API's written in ANSI compatibleC to use and configure the differentfunctionsof InvenSenseMotionTrackingdevices,includingDMP operation.Thistutorial providesasampleproject which sends out fused quaternion data from the accelerometerand gyroscope (6-axis Quaternion)ontotheserialportof thePCwhichis processedbya clientwritten inpythonto displayand rotatea3dimensional cube on the screen.The 6 axis and9 axis InvenSense devices are supported in this driver.The following isaddressed inthis Motion Drivertutorial:Howtoload,configure,and leverageDMPfunctions.I2C driver example for theMSP430.Gyroscope and accelerometer self-test function calls based on the hardware self-test document.-(PleaserefertotheproductRegisterMapdocumentforfullself-testdescriptions)Accelerometercalibrationandupdatingparameterswithin thehardware registers.GyroscopecalibrationConfiguringthelowpoweraccelerometermotion interruptAbility to change the sensor Output Data Rate (ODR) of the gyroscope and accelerometer.-,Abilitytoselectwhichdata ispopulated intheFIFO.4of12CONFIDENTIAL&PROPRIETARY
Embedded Motion Driver 5.1.1 Tutorial Document Number: Revision: 1.0 Release Date: 12/19/2012 CONFIDENTIAL & PROPRIETARY 4 of 12 4. Introduction to Motion Driver Motion Driver consists of a set of API’s written in ANSI compatible C to use and configure the different functions of InvenSense Motion Tracking devices, including DMP operation. This tutorial provides a sample project which sends out fused quaternion data from the accelerometer and gyroscope (6-axis Quaternion) onto the serial port of the PC which is processed by a client written in python to display and rotate a 3 dimensional cube on the screen. The 6 axis and 9 axis InvenSense devices are supported in this driver. The following is addressed in this Motion Driver tutorial: - How to load, configure, and leverage DMP functions. - I2C driver example for the MSP430. - Gyroscope and accelerometer self-test function calls based on the hardware self-test document. (Please refer to the product Register Map document for full self-test descriptions). - Accelerometer calibration and updating parameters within the hardware registers. - Gyroscope calibration - Configuring the low power accelerometer motion interrupt - Ability to change the sensor Output Data Rate (ODR) of the gyroscope and accelerometer. - Ability to select which data is populated in the FIFO
Document Number:Revision:1.0InvenSenseEmbeddedMotionDriver5.1.1TutorialReleaseDate:12/19/20125.OpeninguptheMotionDriverProjectinCodeComposerStudioSelectimportunderthefilemenu.1.2.ChooseexistingCcSeclipseproject3.ClickthebrowsebuttontoselecttheMotionDriverfolderCCSEdit-CodeCompozerStudioexImportCCSEdipseProjeImportil Edt View Nigte Projet Run SerghSelAPEEMSelectNewAt+Si心arsFees existing CCS Ecipse proiects intOpen Fic.ChoBrowPrintSwitch WorlspaceRestatCode ComposerStud4i,BuildVarisboEopedtingCcS?CancelBacFigureShowssteps1to3toopenthemotiondriverprojectOpen the Motion Driver project by clicking finish.4.aildXOOkImportCCS EclipseProjectCCS Eat-Code CompolerStud.Ee Edt View Hirigate Breject Bun Scnipts indoHelpSelect Existing CCS Eclipse Projectccs Deauga书SeectadirecterytosearchforeistingCCSEclipseprojectscCsddiver-2.0 Wetive-ReleneSelect sgarch-directLocalNUMPLMotiontnBrowseSelect archivefileBrowte..dietDiscovered projectsdmpkey.dmomamotien_driver-2.0[C/nvensense_Karthik_LocalUMPLMotioSelect AllDeselect Allinv.gymo.国imv.9oRefreshatUSB_APQCMIPOS8#ROUSE_eMPNo censoles to dilCopy promsp430_dock.Omsp430_clock.Automlyimportreferencedproject1Rsp430_intemupthJpesechdamap430USB.cmc?Leememoticn driver-20BacEinisharFigureshowingthestep4andthefinal IDEwithMotionDriver5.Openthe filemotion drivertest.c underthe simple apps folder.This file will bereferredto asthe“mainfilethroughout this tutorial.Themain file includes examples on howto configuretheMotionDriverandhas in-source documentation to help users readthrough each line of code6.Explaining Motion Driver and theFunctional Specification in More DetailDMP6.1DMPandDMPfeatures:TheDMPisauniquehardwarefeatureofInvenSenseMPUdevices1.which is capable of computing quaternion data from sensor readings,performing devicecalibration,andalsoincludesapplicationspecificfeaturessuchaspedometerstep-counting.TheDMP image(firmware)isheld involatilememoryontheMPUandneedstobeupdatedtothe5of12CONFIDENTIAL&PROPRIETARY
Embedded Motion Driver 5.1.1 Tutorial Document Number: Revision: 1.0 Release Date: 12/19/2012 CONFIDENTIAL & PROPRIETARY 5 of 12 5. Opening up the Motion Driver Project in Code Composer Studio 1. Select import under the file menu. 2. Choose existing CCS eclipse project. 3. Click the browse button to select the Motion Driver folder. Figure Shows steps 1 to 3 to open the motion driver project 4. Open the Motion Driver project by clicking finish. Figure showing the step 4 and the final IDE with Motion Driver 5. Open the file motion_driver_test.c under the simple_apps folder. This file will be referred to as the “main” file throughout this tutorial. The main file includes examples on how to configure the Motion Driver and has in-source documentation to help users read through each line of code. 6. Explaining Motion Driver and the Functional Specification in More Detail 6.1 DMP 1. DMP and DMP features: The DMP is a unique hardware feature of InvenSense MPU devices which is capable of computing quaternion data from sensor readings, performing device calibration, and also includes application specific features such as pedometer step-counting. The DMP image (firmware) is held in volatile memory on the MPU and needs to be updated to the