I2C interface for LG1300L IMU

Dependents:   LG1300L_Hello_World LG1300L_Hello_World_LCD

Committer:
mjenkins11
Date:
Tue Mar 05 04:56:36 2013 +0000
Revision:
2:9bac32f6c9a0
Parent:
1:c40e8dead9be
revision 0.5;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjenkins11 0:896f1d7a0503 1 #include "mbed.h"
mjenkins11 0:896f1d7a0503 2 #ifndef MBED_LG1300L_H
mjenkins11 0:896f1d7a0503 3 #define MBED_LG1300L_H
mjenkins11 1:c40e8dead9be 4 /** CruizCore XG1300L IMU interface
mjenkins11 0:896f1d7a0503 5 * Used for communicating with an XG1300L IMU over I2C
mjenkins11 0:896f1d7a0503 6 * @code
mjenkins11 0:896f1d7a0503 7 *#include "mbed.h"
mjenkins11 0:896f1d7a0503 8 *#include "TextLCD.h"
mjenkins11 0:896f1d7a0503 9 *#include "LG1300L.h"
mjenkins11 0:896f1d7a0503 10 *
mjenkins11 0:896f1d7a0503 11 *TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
mjenkins11 0:896f1d7a0503 12 *
mjenkins11 0:896f1d7a0503 13 *Serial pc(USBTX, USBRX); // tx, rx
mjenkins11 0:896f1d7a0503 14 *
mjenkins11 0:896f1d7a0503 15 *I2C i2c(p28,p27);
mjenkins11 0:896f1d7a0503 16 *DigitalOut LED (LED1);
mjenkins11 0:896f1d7a0503 17 *
mjenkins11 0:896f1d7a0503 18 *int main() {
mjenkins11 0:896f1d7a0503 19 * LG1300L IMU(i2c, 2);
mjenkins11 0:896f1d7a0503 20 *
mjenkins11 0:896f1d7a0503 21 * while(1) {
mjenkins11 0:896f1d7a0503 22 * float angle = IMU.GetAngle();
mjenkins11 0:896f1d7a0503 23 * float ROT= IMU.GetROT();
mjenkins11 0:896f1d7a0503 24 * float X_ACC = IMU.GetACC_X();
mjenkins11 0:896f1d7a0503 25 * float Y_ACC = IMU. GetACC_Y();
mjenkins11 0:896f1d7a0503 26 * float Z_ACC = IMU. GetACC_Z();
mjenkins11 0:896f1d7a0503 27 * pc.printf("///////////////////////////////////\n");
mjenkins11 0:896f1d7a0503 28 * pc.printf("//ANGLE: %f\n", angle);
mjenkins11 0:896f1d7a0503 29 * pc.printf("//ROT: %f\n", ROT);
mjenkins11 0:896f1d7a0503 30 * pc.printf("//X-Axis: %f\n", X_ACC );
mjenkins11 0:896f1d7a0503 31 * pc.printf("//Y-Axis: %f\n", Y_ACC );
mjenkins11 0:896f1d7a0503 32 * pc.printf("//Z-axis: %f\n", Z_ACC );
mjenkins11 0:896f1d7a0503 33 * pc.printf("///////////////////////////////////\n");
mjenkins11 0:896f1d7a0503 34 * wait(1);
mjenkins11 0:896f1d7a0503 35 * }
mjenkins11 0:896f1d7a0503 36 *}
mjenkins11 0:896f1d7a0503 37 * @endcode
mjenkins11 0:896f1d7a0503 38 */
mjenkins11 0:896f1d7a0503 39
mjenkins11 0:896f1d7a0503 40
mjenkins11 0:896f1d7a0503 41
mjenkins11 0:896f1d7a0503 42
mjenkins11 0:896f1d7a0503 43 class LG1300L{
mjenkins11 0:896f1d7a0503 44 public:
mjenkins11 0:896f1d7a0503 45
mjenkins11 1:c40e8dead9be 46 /** Create an IMU readout interface
mjenkins11 0:896f1d7a0503 47 *
mjenkins11 0:896f1d7a0503 48 * @param i2c The instantiated I2C bus to be used
mjenkins11 0:896f1d7a0503 49 * @param ACC_SETTING the desired initialization range for the
mjenkins11 1:c40e8dead9be 50 * @note Create an IMU readout interface
mjenkins11 0:896f1d7a0503 51 accelerometers, choices are +-2G, +-4G, or +-8G
mjenkins11 0:896f1d7a0503 52 */
mjenkins11 0:896f1d7a0503 53 LG1300L(I2C& i2c, int ACC_SETTING);
mjenkins11 0:896f1d7a0503 54
mjenkins11 1:c40e8dead9be 55 /** Returns a float containing the current Accumulated Angle
mjenkins11 2:9bac32f6c9a0 56 * @returns the Accumulated Angle
mjenkins11 0:896f1d7a0503 57 */
mjenkins11 0:896f1d7a0503 58 float GetAngle();
mjenkins11 1:c40e8dead9be 59 /** Returns a float containing the current ROT
mjenkins11 2:9bac32f6c9a0 60 * @returns the Rate of Turn
mjenkins11 0:896f1d7a0503 61 */
mjenkins11 0:896f1d7a0503 62 float GetROT();
mjenkins11 1:c40e8dead9be 63 /** Returns a float containing the current acceleration on
mjenkins11 0:896f1d7a0503 64 * the X axis.
mjenkins11 2:9bac32f6c9a0 65 * @returns the acceleration on the X_Axis
mjenkins11 0:896f1d7a0503 66 *
mjenkins11 0:896f1d7a0503 67 */
mjenkins11 0:896f1d7a0503 68 float GetACC_X();
mjenkins11 1:c40e8dead9be 69 /** Returns a float containing the current acceleration on
mjenkins11 0:896f1d7a0503 70 *the Y axis.
mjenkins11 2:9bac32f6c9a0 71 * @returns the acceleration on the Y_Axis
mjenkins11 0:896f1d7a0503 72 */
mjenkins11 0:896f1d7a0503 73 float GetACC_Y();
mjenkins11 1:c40e8dead9be 74 /** Returns a float containing the current acceleration on
mjenkins11 0:896f1d7a0503 75 *the Z axis.
mjenkins11 2:9bac32f6c9a0 76 * @returns the acceleration on the Z_Axis
mjenkins11 0:896f1d7a0503 77 */
mjenkins11 0:896f1d7a0503 78 float GetACC_Z();
mjenkins11 0:896f1d7a0503 79 private:
mjenkins11 0:896f1d7a0503 80
mjenkins11 0:896f1d7a0503 81 void init();
mjenkins11 0:896f1d7a0503 82
mjenkins11 0:896f1d7a0503 83 char ANGLE_LSB_REG[1];
mjenkins11 0:896f1d7a0503 84 char ANGLE_MSB_REG[1];
mjenkins11 0:896f1d7a0503 85 char ROT_LSB_REG[1];
mjenkins11 0:896f1d7a0503 86 char ROT_MSB_REG[1];
mjenkins11 0:896f1d7a0503 87 char X_ACC_LSB_REG[1];
mjenkins11 0:896f1d7a0503 88 char X_ACC_MSB_REG[1];
mjenkins11 0:896f1d7a0503 89 char Y_ACC_LSB_REG[1];
mjenkins11 0:896f1d7a0503 90 char Y_ACC_MSB_REG[1];
mjenkins11 0:896f1d7a0503 91 char Z_ACC_LSB_REG[1];
mjenkins11 0:896f1d7a0503 92 char Z_ACC_MSB_REG[1];
mjenkins11 0:896f1d7a0503 93
mjenkins11 0:896f1d7a0503 94
mjenkins11 0:896f1d7a0503 95 char RESET_REG[1];
mjenkins11 0:896f1d7a0503 96 char SELECT_2G_REG[1];
mjenkins11 0:896f1d7a0503 97 char SELECT_4G_REG[1];
mjenkins11 0:896f1d7a0503 98 char SELECT_8G_REG[1];
mjenkins11 0:896f1d7a0503 99
mjenkins11 0:896f1d7a0503 100 float CALC_ANG, CALC_ROT, CALC_X, CALC_Y, CALC_Z;
mjenkins11 0:896f1d7a0503 101 int ACC_RANGE;
mjenkins11 0:896f1d7a0503 102 signed short ANGLE_MSB;
mjenkins11 0:896f1d7a0503 103 signed short ANGLE_LSB;
mjenkins11 0:896f1d7a0503 104 signed short ROT_MSB;
mjenkins11 0:896f1d7a0503 105 signed short ROT_LSB;
mjenkins11 0:896f1d7a0503 106 signed short ACC_X_MSB;
mjenkins11 0:896f1d7a0503 107 signed short ACC_X_LSB;
mjenkins11 0:896f1d7a0503 108 signed short ACC_Y_MSB;
mjenkins11 0:896f1d7a0503 109 signed short ACC_Y_LSB;
mjenkins11 0:896f1d7a0503 110 signed short ACC_Z_MSB;
mjenkins11 0:896f1d7a0503 111 signed short ACC_Z_LSB;
mjenkins11 0:896f1d7a0503 112 protected:
mjenkins11 0:896f1d7a0503 113
mjenkins11 0:896f1d7a0503 114 I2C& IMU;
mjenkins11 0:896f1d7a0503 115 char data[2];
mjenkins11 0:896f1d7a0503 116 const int IMU_ADDR;
mjenkins11 0:896f1d7a0503 117 };
mjenkins11 0:896f1d7a0503 118
mjenkins11 0:896f1d7a0503 119 #endif