Minor fixes

Dependencies:   LSM9DS1_Library SDFileSystem mbed nrf51_rtc

Fork of LSM303DLHTest by Toshihisa T

Revision:
7:cbfdcc57f110
Parent:
6:9db9f4bfaf98
Child:
8:8f4d7f1c588f
diff -r 9db9f4bfaf98 -r cbfdcc57f110 main.cpp
--- a/main.cpp	Fri Jul 15 22:39:42 2016 +0000
+++ b/main.cpp	Tue Jul 19 20:53:52 2016 +0000
@@ -14,7 +14,7 @@
 Serial debug(USBTX,USBRX);
 // For Nordic
 LSM9DS1 lol(p30, p7, 0xD6, 0x3C);
-
+I2C i2c(p30, p7);
 // Create the SD filesystem
 SDFileSystem sd(p25, p28, p29, p20, "sd"); // MOSI, MISO, SCLK, SSEL
 
@@ -48,10 +48,36 @@
     start = 0;
 }
 
-// Fillped every second
+void parp( int times )
+{
+    int i;
+    for( i = 0; i < times; i++) {
+        led1 = 0;
+        wait( 0.05);
+        led1 = 1;
+        wait( 0.05);
+    }
+    led2 = 1;
+}
+// Flipped every second
 void flip()
 {
-    led2 = !led2;
+    led2 = 0;
+    wait(0.01);
+    led2 = 1;
+}
+
+
+uint8_t I2CreadByte(uint8_t address, uint8_t subAddress)
+{
+    char data;
+    char temp= subAddress;
+
+    //i2c.write(address, temp, 1);
+    //temp[1] = 0x00;
+    i2c.write(address, &temp, 1);
+    int a = i2c.read(address, &data, 1);
+    return data;
 }
 
 int main()
@@ -76,12 +102,51 @@
     debug.printf("LSM303DLH Test\x0d\x0a");
 
     // Initialize 9DOF
-    lol.begin();
+    //lol.begin();
     if (!lol.begin()) {
         debug.printf("Failed to communicate with LSM9DS1.\n");
     }
     lol.calibrate();
 
+    lol.configInt(XG_INT1, INT1_IG_G|INT1_IG_XL,     INT_ACTIVE_LOW, INT_PUSH_PULL);   //INT1_CTRL (0x0C) + CTRL_REG8 (0x22)
+    lol.configInt(XG_INT2, INT2_DRDY_G|INT2_DRDY_XL, INT_ACTIVE_LOW, INT_PUSH_PULL);   //INT2_CTRL (0x0D) + CTRL_REG8 (0x22)
+
+    lol.configAccelInt(YHIE_XL|XHIE_XL, false);                                        // INT_GEN_CFG_XL (06h)
+    lol.configAccelThs((uint8_t)0x25, X_AXIS, (uint8_t)0x00, false);                   // INT_GEN_THS_X_XL (07h)
+    lol.configAccelThs((uint8_t)0x25, Y_AXIS, (uint8_t)0x00, false);                   // INT_GEN_THS_Y_XL (08h)
+    lol.configAccelThs((uint8_t)0x25, Z_AXIS, (uint8_t)0x00, false);                   // INT_GEN_THS_Z_XL (09h)
+
+    lol.configGyroInt(ZLIE_G|YLIE_G|XLIE_G, false, true);                              // INT_GEN_CFG_G (30h)
+    lol.configGyroThs((int16_t )0x300, X_AXIS, (uint8_t) 0x00, false);                 // INT_GEN_THS_X_G (31h - 32h)
+    lol.configGyroThs((int16_t )0x300, Y_AXIS, (uint8_t) 0x00, false);                 // INT_GEN_THS_Y_G (33h - 34h)
+    lol.configGyroThs((int16_t )0x300, Z_AXIS, (uint8_t) 0x00, false);                 // INT_GEN_THS_Z_G (35h - 36h)
+    debug.printf( "\n\r");
+    debug.printf( "GyroIntSrc (14h) %02x\n\r", lol.getGyroIntSrc());                        // INT_GEN_SRC_G (14h)
+    debug.printf( "AccelIntSrc(26h) %02x\n\r", lol.getAccelIntSrc());                       // INT_GEN_SRC_XL (26h)
+    debug.printf( "MagIntSrc  (31h) %02x\n\r", lol.getMagIntSrc());                         // INT_SRC_M (31h)
+    debug.printf( "Inactivity (17h) %02x\n\r", lol.getInactivity());                        // STATUS_REG (17h)
+
+    debug.printf( "INT1_CTRL        (0Ch) %02x\n\r", I2CreadByte(0xD6, 0x0C));
+    debug.printf( "INT2_CTRL        (0CD) %02x\n\r", I2CreadByte(0xD6, 0x0D));
+    debug.printf( "CTRL_REG8        (22h) %02x\n\r", I2CreadByte(0xD6, 0x22));
+    debug.printf( "\n\r");
+    debug.printf( "INT_GEN_CFG_XL   (06h) %02x\n\r", I2CreadByte(0xD6, 0x06));
+    debug.printf( "INT_GEN_SRC_XL   (26h) %02x\n\r", I2CreadByte(0xD6, 0x26));
+    debug.printf( "INT_GEN_THS_X_XL (07h) %02x\n\r", I2CreadByte(0xD6, 0x07));
+    debug.printf( "INT_GEN_THS_Y_XL (08h) %02x\n\r", I2CreadByte(0xD6, 0x08));
+    debug.printf( "INT_GEN_THS_Z_XL (09h) %02x\n\r", I2CreadByte(0xD6, 0x09));
+    debug.printf( "INT_GEN_DUR_XL   (0ah) %02x\n\r", I2CreadByte(0xD6, 0x0a));
+    debug.printf( "\n\r");
+    debug.printf( "INT_GEN_CFG_G    (30h) %02x\n\r", I2CreadByte(0xD6, 0x30));
+    debug.printf( "INT_GEN_SRC_G    (14h) %02x\n\r", I2CreadByte(0xD6, 0x14));
+    debug.printf( "INT_GEN_THS_XH_G (31h) %02x\n\r", I2CreadByte(0xD6, 0x31));
+    debug.printf( "INT_GEN_THS_XL_G (32h) %02x\n\r", I2CreadByte(0xD6, 0x32));
+    debug.printf( "INT_GEN_THS_YH_G (33h) %02x\n\r", I2CreadByte(0xD6, 0x33));
+    debug.printf( "INT_GEN_THS_YL_G (34h) %02x\n\r", I2CreadByte(0xD6, 0x34));
+    debug.printf( "INT_GEN_THS_ZH_G (35h) %02x\n\r", I2CreadByte(0xD6, 0x35));
+    debug.printf( "INT_GEN_THS_ZL_G (36h) %02x\n\r", I2CreadByte(0xD6, 0x36));
+    debug.printf( "INT_GEN_DUR_G    (37h) %02x\n\r", I2CreadByte(0xD6, 0x37));
+
 //    // Initialize current time if needed
 //    printf("Enter current date and time:\n");
 //    printf("YYYY MM DD HH MM SS[enter]\n");
@@ -103,7 +168,8 @@
             led1 = 1;
         }
         // Start sampling
-        led1 = 0;
+        //led1 = 0;
+        parp(5);
         debug.printf("Started sampling\n\r");
         // Get the time and create a file with the number of seconds in hex appended
         seconds = rtc.time();
@@ -124,7 +190,7 @@
 
         // Sample until button 2 is pressed
         while(!stop) {
-            led1 = 0;
+            //led1 = 0;
             lol.readAccel();
             lol.readMag();
             lol.readGyro();
@@ -137,9 +203,13 @@
             wait(0.1);
         }
         // Stop Sampling and close file
+        parp(10);
         led1 = 1;
         debug.printf("Stopped sampling\n\r");
         debug.printf("Results stored in %s\n\r", filename);
         fclose(fp);
     }
 }
+
+
+