L3G4200D SPI driver. Runs at 10mhz vs I2C 400khz. High pass filtered data sets a INT1 pin high when a reference threshold is reached on an axis. Returns the axis that reached the threshold and the DPS of that threshold. Threshold levels can be tweaked by editing void setupL3G4200D()

Dependencies:   mbed

Committer:
Spilly
Date:
Tue Nov 25 15:27:47 2014 +0000
Revision:
0:66fe7a32bd59
First release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Spilly 0:66fe7a32bd59 1 /***********************************************************************************************/
Spilly 0:66fe7a32bd59 2 //Ryan Spillman
Spilly 0:66fe7a32bd59 3 //11/23/2014
Spilly 0:66fe7a32bd59 4 //
Spilly 0:66fe7a32bd59 5 //This is a small piece of a Dead Reckoning robotics project
Spilly 0:66fe7a32bd59 6 //
Spilly 0:66fe7a32bd59 7 //High pass filtered, bias corrected, L3G4200D SPI driver
Spilly 0:66fe7a32bd59 8 //
Spilly 0:66fe7a32bd59 9 //In a later revision, will integrate DPS to approximate position
Spilly 0:66fe7a32bd59 10 //
Spilly 0:66fe7a32bd59 11 //FRDM-K64F Connections
Spilly 0:66fe7a32bd59 12 //MOSI, MISO, SCK, CS, INT1
Spilly 0:66fe7a32bd59 13 //PTD6, PTD7, PTD5, PTD4, PTC16
Spilly 0:66fe7a32bd59 14 /***********************************************************************************************/
Spilly 0:66fe7a32bd59 15
Spilly 0:66fe7a32bd59 16 #include "L3G4200D.h"
Spilly 0:66fe7a32bd59 17
Spilly 0:66fe7a32bd59 18 //Serial pc(USBTX, USBRX);
Spilly 0:66fe7a32bd59 19
Spilly 0:66fe7a32bd59 20
Spilly 0:66fe7a32bd59 21
Spilly 0:66fe7a32bd59 22 //Prototype function
Spilly 0:66fe7a32bd59 23 void checkGyro();
Spilly 0:66fe7a32bd59 24
Spilly 0:66fe7a32bd59 25 int main()
Spilly 0:66fe7a32bd59 26 {
Spilly 0:66fe7a32bd59 27 pc.baud(115200);
Spilly 0:66fe7a32bd59 28
Spilly 0:66fe7a32bd59 29 wait(1);
Spilly 0:66fe7a32bd59 30
Spilly 0:66fe7a32bd59 31 setupL3G4200D(); // Configure L3G4200
Spilly 0:66fe7a32bd59 32
Spilly 0:66fe7a32bd59 33 wait(1);
Spilly 0:66fe7a32bd59 34
Spilly 0:66fe7a32bd59 35 setRef();
Spilly 0:66fe7a32bd59 36 //getGyroBias(); //Device must be stationary while calculating bias
Spilly 0:66fe7a32bd59 37
Spilly 0:66fe7a32bd59 38 while(1)
Spilly 0:66fe7a32bd59 39 {
Spilly 0:66fe7a32bd59 40 //Wait until INT1 pin goes active before reading gyro
Spilly 0:66fe7a32bd59 41 while(!INT1);
Spilly 0:66fe7a32bd59 42 /*
Spilly 0:66fe7a32bd59 43 getGyroValues();
Spilly 0:66fe7a32bd59 44
Spilly 0:66fe7a32bd59 45 for(int i = 0; i < 3; i++)
Spilly 0:66fe7a32bd59 46 {
Spilly 0:66fe7a32bd59 47 pc.printf("%i\t", gyro[i]);
Spilly 0:66fe7a32bd59 48 }
Spilly 0:66fe7a32bd59 49
Spilly 0:66fe7a32bd59 50
Spilly 0:66fe7a32bd59 51 pc.printf("\n");
Spilly 0:66fe7a32bd59 52 */
Spilly 0:66fe7a32bd59 53 checkGyro();
Spilly 0:66fe7a32bd59 54
Spilly 0:66fe7a32bd59 55 }
Spilly 0:66fe7a32bd59 56 }