i2c trial - does'nt work

Dependencies:   ACD_ePaper aconno_I2C aconno_bsp mbed

Fork of acd52832_LSM9DS1 by Jurica Resetar

Files at this revision

API Documentation at this revision

Comitter:
med2017
Date:
Wed Feb 14 21:16:43 2018 +0000
Parent:
0:940647793667
Commit message:
testing

Changed in this revision

LSM9DS1/LSM9DS1.cpp Show annotated file Show diff for this revision Revisions of this file
LSM9DS1/LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
LSM9DS1/LSM9DS1_defVals.h Show annotated file Show diff for this revision Revisions of this file
LSM9DS1/LSM9DS1_regs.h Show annotated file Show diff for this revision Revisions of this file
LSM9DS1_defVals.h Show diff for this revision Revisions of this file
LSM9DS1_regs.h Show diff for this revision Revisions of this file
aconno_I2C.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 940647793667 -r e97c56fb9629 LSM9DS1/LSM9DS1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1/LSM9DS1.cpp	Wed Feb 14 21:16:43 2018 +0000
@@ -0,0 +1,169 @@
+#include "LSM9DS1.h"
+#include "mbed.h"
+#include "aconno_i2c.h"
+
+LSM9DS1::LSM9DS1(I2C *i2c_, char address) : i2c(i2c_, address){
+}
+
+/*uint8_t LSM9DS1::whoIAm(){
+    char regAddr = (char)WHO_AM_I;
+    char regData;
+    i2c.readFromReg(regAddr, &regData, 1);
+    return (uint8_t)regData;
+}
+*/
+uint8_t LSM9DS1::setMode(Mode mode){
+    char ctrl1Copy;
+    char ctrl4Copy;
+    uint8_t success;
+    
+    //i2c.readFromReg((char)CTRL_REG1, &ctrl1Copy, 1); 
+    //i2c.readFromReg((char)CTRL_REG4, &ctrl4Copy, 1);
+    
+/* DONT NEED TO SWITCH MODE CAUSE JUST USING ACCELERATION
+
+    switch(mode){
+        case HIGH_RES:
+            ctrl1Copy &= 0xF7;
+            ctrl4Copy |= 0x08;
+            break;
+        case NORMAL:
+            ctrl1Copy &= 0xF7;
+            ctrl4Copy &= 0xF7;
+            break;
+        case LOW_POWER:
+            ctrl1Copy |= 0x08;
+            ctrl4Copy &= 0xF7;
+            break;
+        default:
+            return 0;
+    }
+    i2c.writeToReg((char)CTRL_REG5_XL, &ctrl1Copy, 1);
+    success = i2c.writeToReg((char)CTRL_REG6_XL, &ctrl4Copy, 1);
+    return success;
+}
+
+*/
+
+uint8_t LSM9DS1::enableAxes(Axis axis){
+    char ctrl1Copy;
+    i2c.readFromReg((char)CTRL_REG5_XL, &ctrl1Copy, 1);
+    ctrl1Copy |= axis;
+    i2c.writeToReg((char)CTRL_REG6_XL, &ctrl1Copy, 1);
+    return 0;
+}
+
+uint8_t LSM9DS1::disableAxes(Axis axis){
+    char ctrl1Copy;
+    i2c.readFromReg((char)CTRL_REG5_XL, &ctrl1Copy, 1);
+    ctrl1Copy &= ~(1 << axis);
+    i2c.writeToReg((char)CTRL_REG6_XL, &ctrl1Copy, 1);
+    return 0;
+}
+
+int16_t LSM9DS1::readXAxis(){
+    int16_t rawData;
+    char tempData;
+    // Make sure new data is ready
+    do{
+        i2c.readFromReg((char)STATUS_REG_0, &tempData, 1);
+    }while(!(tempData & 0x08));
+    do{
+        i2c.readFromReg((char)STATUS_REG_0, &tempData, 1);
+    }while(!(tempData & 0x80));
+    // Same data have been overwritten
+    
+    i2c.readFromReg((char)OUT_X_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_X_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+int16_t LSM9DS1::readYAxis(){
+    int16_t rawData;
+    char tempData;
+    i2c.readFromReg((char)OUT_Y_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_Y_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+int16_t LSM9DS1::readZAxis(){
+    int16_t rawData;
+    char tempData;
+    i2c.readFromReg((char)OUT_Z_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_Z_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+//uint8_t LSM9DS1::setODR(Odr odr){
+  //  char ctrl1Copy;
+    //i2c.readFromReg((char)CTRL_REG8, &ctrl1Copy, 1);
+    //ctrl1Copy |= (odr << 4);
+    //i2c.writeToReg((char)CTRL_REG8, &ctrl1Copy, 1);
+    //return 0;
+//}
+
+/*uint8_t LSM9DS1::setScale(Scale scale){
+    char ctrl4Copy;
+    i2c.readFromReg((char)CTRL_REG9, &ctrl4Copy, 1);
+    ctrl4Copy |= (scale << 4);
+    i2c.writeToReg((char)CTRL_REG9, &ctrl4Copy, 1);
+    return 0;
+}
+*?
+
+/* Interrupt activity 1 driven to INT1 pad */
+
+/*
+uint8_t LSM9DS1::int1Setup(uint8_t setup){
+    char data = setup;
+    i2c.writeToReg((char)CTRL_REG6_XL, &data, 1);
+    return 0;
+}
+
+
+*/
+
+
+/*uint8_t LSM9DS1::int1Latch(uint8_t enable){
+    char ctrl5Copy;
+    i2c.readFromReg((char)CTRL_REG5, &ctrl5Copy, 1); //reg for magnetometer
+    ctrl5Copy |= enable;
+    i2c.writeToReg((char)CTRL_REG5, &ctrl5Copy, 1);
+    return 0; 
+}
+*/
+
+/*uint8_t LSM9DS1::int1Duration(uint8_t duration){
+    char copy = duration;
+    i2c.writeToReg((char)INT1_DURATION, &copy, 1);//reg for magnetometer
+    return 0;
+}
+*/
+
+
+/*
+uint8_t LSM9DS1::int1Threshold(uint8_t threshold){
+    char copy = threshold;
+    i2c.writeToReg((char)INT1_THS, &copy, 1);
+    return 0;
+}
+
+uint8_t LSM9DS1::int1Config(uint8_t config){
+    char copy = config;
+    i2c.writeToReg((char)INT1_CFG, &copy, 1);
+    return 0;
+}
+
+void LSM9DS1::clearIntFlag(){
+    char data;
+    i2c.readFromReg((char)INT1_SRC, (char*)&data, 1);
+}
+
+*/
+ 
\ No newline at end of file
diff -r 940647793667 -r e97c56fb9629 LSM9DS1/LSM9DS1.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1/LSM9DS1.h	Wed Feb 14 21:16:43 2018 +0000
@@ -0,0 +1,85 @@
+
+ 
+#ifndef LSM9DS1_H
+#define LSM9DS1_H
+
+#include "mbed.h"
+#include "aconno_i2c.h"
+#include "LSM9DS1_regs.h"
+#include "LSM9DS1_defVals.h"
+
+
+//TO DO: once i2c sucessfully works come back to this for fine tuning data
+
+
+
+enum Mode{
+    HIGH_RES = 0,
+    NORMAL,
+    LOW_POWER,
+};
+
+enum Axis{
+    X_axis = 0x01,
+    Y_axis = 0x02,
+    Z_axis = 0x04,
+};
+
+enum Odr{
+    PowerDown = 0x00,
+    ODR_1Hz = 0x01,
+    ODR_10Hz = 0x02,
+    ODR_25Hz = 0x03,
+    ODR_50Hz = 0x04,
+    ODR_100Hz = 0x05,
+    ODR_200Hz = 0x06,
+    ODR_400Hz = 0x07,
+    ODR_1620Hz = 0x08,
+    ODR_Max = 0x09,         // HighRes/Normal -> 1.344kHz, LowPower -> 5.376kHz
+};
+
+enum Scale{
+    _2g = 0x00,
+    _4g = 0x01,
+    _8g = 0x02,
+    _16g = 0x03,
+};
+
+
+class LSM9DS1{
+    public:
+        LSM9DS1(I2C *i2c_, char address);
+        uint8_t whoIAm();
+        uint8_t setMode(Mode mode);
+        uint8_t enableAxes(Axis axis);
+        uint8_t disableAxes(Axis axis);
+        int16_t readXAxis();
+        int16_t readYAxis();
+        int16_t readZAxis();
+        uint8_t setODR(Odr odr);
+        uint8_t setScale(Scale scale);
+        uint8_t int1Setup(uint8_t setup);
+        uint8_t int1Latch(uint8_t enable);
+        uint8_t int1Duration(uint8_t duration);
+        uint8_t int1Threshold(uint8_t threshold);
+        uint8_t int1Config(uint8_t config);
+        void clearIntFlag();
+
+/*        
+    public:
+        LSM9DS1(I2C i2c);
+        void startMag(void);
+        void readMag(int16_t *results);
+        void startAcc(void);
+        void readAcc(int16_t *results);
+        void startGyro(void);
+        void readGyro(int16_t *results);    
+   */ 
+    private:
+        aconno_i2c i2c;
+         
+};
+
+
+#endif
+ 
\ No newline at end of file
diff -r 940647793667 -r e97c56fb9629 LSM9DS1/LSM9DS1_defVals.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1/LSM9DS1_defVals.h	Wed Feb 14 21:16:43 2018 +0000
@@ -0,0 +1,21 @@
+/* Copyright (c) 2016 Aconno. All Rights Reserved.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+ 
+ 
+ #define M_SCALE16GS            3
+ #define M_ODR_80               7
+ 
+ #define M_ENABLE               1               // True
+ #define M_SCALE                M_SCALE_16GS
+ #define M_SAMPLE_RATE          M_ODR_80
+ #define M_XY_PERFORMANCE       3
+ #define M_Z_PERFORMANCE        3
+ #define M_LOW_POWER_ENABLE     0               // False
+ #define M_OPERATING_MODE       0
+ 
+ 
\ No newline at end of file
diff -r 940647793667 -r e97c56fb9629 LSM9DS1/LSM9DS1_regs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1/LSM9DS1_regs.h	Wed Feb 14 21:16:43 2018 +0000
@@ -0,0 +1,87 @@
+/* Copyright (c) 2016 Aconno. All Rights Reserved.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+ 
+ //Magnetometer I2C address
+ #define TWI_MAG_ADDR           (0x1C << 1)  
+ 
+//Accelerometer and Gyroscope registars addresses
+#define ACT_THS                 0x04  
+#define ACT_DUR                 0x05
+#define INT_GEN_CFG_XL          0x06
+#define INT_GEN_THS_X_XL        0x07
+#define INT_GEN_THS_Y_XL        0x08
+#define INT_GEN_THS_Z_XL        0x09
+#define INT_GEN_DUR_XL          0x0A
+#define REFERENCE_G             0x0B
+#define INT1_CTRL               0x0C
+#define INT2_CTRL               0x0D
+#define WHO_AM_I_XG             0x0F
+#define CTRL_REG1_G             0x10
+#define CTRL_REG2_G             0x11
+#define CTRL_REG3_G             0x12
+#define ORIENT_CFG_G            0x13
+#define INT_GEN_SRC_G           0x14
+#define OUT_TEMP_L              0x15
+#define OUT_TEMP_H              0x16
+#define STATUS_REG_0            0x17
+#define OUT_X_L_G               0x18
+#define OUT_X_H_G               0x19
+#define OUT_Y_L_G               0x1A
+#define OUT_Y_H_G               0x1B
+#define OUT_Z_L_G               0x1C
+#define OUT_Z_H_G               0x1D
+#define CTRL_REG4               0x1E
+#define CTRL_REG5_XL            0x1F ///////////ACCEL
+#define CTRL_REG6_XL            0x20
+#define CTRL_REG7_XL            0x21
+#define CTRL_REG8               0x22
+#define CTRL_REG9               0x23
+#define CTRL_REG10              0x24
+#define INT_GEN_SRC_XL          0x26
+#define STATUS_REG_1            0x27
+#define OUT_X_L_XL              0x28 //////////////////////
+#define OUT_X_H_XL              0x29
+#define OUT_Y_L_XL              0x2A
+#define OUT_Y_H_XL              0x2B
+#define OUT_Z_L_XL              0x2C
+#define OUT_Z_H_XL              0x2D
+#define FIFO_CTRL               0x2E
+#define FIFO_SRC                0x2F
+#define INT_GEN_CFG_G           0x30
+#define INT_GEN_THS_XH_G        0x31
+#define INT_GEN_THS_XL_G        0x32
+#define INT_GEN_THS_YH_G        0x33
+#define INT_GEN_THS_YL_G        0x34
+#define INT_GEN_THS_ZH_G        0x35
+#define INT_GEN_THS_ZL_G        0x36
+#define INT_GEN_DUR_G           0x37
+
+//Magnetometer registers addresses
+#define OFFSET_X_REG_L_M        0x05
+#define OFFSET_X_REG_H_M        0x06
+#define OFFSET_Y_REG_L_M        0x07
+#define OFFSET_Y_REG_H_M        0x08
+#define OFFSET_Z_REG_L_M        0x09
+#define OFFSET_Z_REG_H_M        0x0A
+#define WHO_AM_I_M              0x0F
+#define CTRL_REG1_M             0x20
+#define CTRL_REG2_M             0x21
+#define CTRL_REG3_M             0x22
+#define CTRL_REG4_M             0x23
+#define CTRL_REG5_M             0x24
+#define STATUS_REG_M            0x27
+#define OUT_X_L_M               0x28
+#define OUT_X_H_M               0x29
+#define OUT_Y_L_M               0x2A
+#define OUT_Y_H_M               0x2B
+#define OUT_Z_L_M               0x2C
+#define OUT_Z_H_M               0x2D
+#define INT_CFG_M               0x30
+#define INT_SRC_M               0x30
+#define INT_THS_L_M             0x32
+#define INT_THS_H_M             0x33
diff -r 940647793667 -r e97c56fb9629 LSM9DS1_defVals.h
--- a/LSM9DS1_defVals.h	Thu Sep 22 11:38:40 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-/* Copyright (c) 2016 Aconno. All Rights Reserved.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
- 
- 
- #define M_SCALE16GS            3
- #define M_ODR_80               7
- 
- #define M_ENABLE               1               // True
- #define M_SCALE                M_SCALE_16GS
- #define M_SAMPLE_RATE          M_ODR_80
- #define M_XY_PERFORMANCE       3
- #define M_Z_PERFORMANCE        3
- #define M_LOW_POWER_ENABLE     0               // False
- #define M_OPERATING_MODE       0
- 
- 
\ No newline at end of file
diff -r 940647793667 -r e97c56fb9629 LSM9DS1_regs.h
--- a/LSM9DS1_regs.h	Thu Sep 22 11:38:40 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/* Copyright (c) 2016 Aconno. All Rights Reserved.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
- 
- //Magnetometer I2C address
- #define TWI_MAG_ADDR           (0x1C << 1)  
- 
-//Accelerometer and Gyroscope registars addresses
-#define ACT_THS                 0x04  
-#define ACT_DUR                 0x05
-#define INT_GEN_CFG_XL          0x06
-#define INT_GEN_THS_X_XL        0x07
-#define INT_GEN_THS_Y_XL        0x08
-#define INT_GEN_THS_Z_XL        0x09
-#define INT_GEN_DUR_XL          0x0A
-#define REFERENCE_G             0x0B
-#define INT1_CTRL               0x0C
-#define INT2_CTRL               0x0D
-#define WHO_AM_I_XG             0x0F
-#define CTRL_REG1_G             0x10
-#define CTRL_REG2_G             0x11
-#define CTRL_REG3_G             0x12
-#define ORIENT_CFG_G            0x13
-#define INT_GEN_SRC_G           0x14
-#define OUT_TEMP_L              0x15
-#define OUT_TEMP_H              0x16
-#define STATUS_REG_0            0x17
-#define OUT_X_L_G               0x18
-#define OUT_X_H_G               0x19
-#define OUT_Y_L_G               0x1A
-#define OUT_Y_H_G               0x1B
-#define OUT_Z_L_G               0x1C
-#define OUT_Z_H_G               0x1D
-#define CTRL_REG4               0x1E
-#define CTRL_REG5_XL            0x1F
-#define CTRL_REG6_XL            0x20
-#define CTRL_REG7_XL            0x21
-#define CTRL_REG8               0x22
-#define CTRL_REG9               0x23
-#define CTRL_REG10              0x24
-#define INT_GEN_SRC_XL          0x26
-#define STATUS_REG_1            0x27
-#define OUT_X_L_XL              0x28
-#define OUT_X_H_XL              0x29
-#define OUT_Y_L_XL              0x2A
-#define OUT_Y_H_XL              0x2B
-#define OUT_Z_L_XL              0x2C
-#define OUT_Z_H_XL              0x2D
-#define FIFO_CTRL               0x2E
-#define FIFO_SRC                0x2F
-#define INT_GEN_CFG_G           0x30
-#define INT_GEN_THS_XH_G        0x31
-#define INT_GEN_THS_XL_G        0x32
-#define INT_GEN_THS_YH_G        0x33
-#define INT_GEN_THS_YL_G        0x34
-#define INT_GEN_THS_ZH_G        0x35
-#define INT_GEN_THS_ZL_G        0x36
-#define INT_GEN_DUR_G           0x37
-
-//Magnetometer registers addresses
-#define OFFSET_X_REG_L_M        0x05
-#define OFFSET_X_REG_H_M        0x06
-#define OFFSET_Y_REG_L_M        0x07
-#define OFFSET_Y_REG_H_M        0x08
-#define OFFSET_Z_REG_L_M        0x09
-#define OFFSET_Z_REG_H_M        0x0A
-#define WHO_AM_I_M              0x0F
-#define CTRL_REG1_M             0x20
-#define CTRL_REG2_M             0x21
-#define CTRL_REG3_M             0x22
-#define CTRL_REG4_M             0x23
-#define CTRL_REG5_M             0x24
-#define STATUS_REG_M            0x27
-#define OUT_X_L_M               0x28
-#define OUT_X_H_M               0x29
-#define OUT_Y_L_M               0x2A
-#define OUT_Y_H_M               0x2B
-#define OUT_Z_L_M               0x2C
-#define OUT_Z_H_M               0x2D
-#define INT_CFG_M               0x30
-#define INT_SRC_M               0x30
-#define INT_THS_L_M             0x32
-#define INT_THS_H_M             0x33
diff -r 940647793667 -r e97c56fb9629 aconno_I2C.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_I2C.lib	Wed Feb 14 21:16:43 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jurica238814/code/aconno_I2C/#3c0eab894a4b
diff -r 940647793667 -r e97c56fb9629 main.cpp
--- a/main.cpp	Thu Sep 22 11:38:40 2016 +0000
+++ b/main.cpp	Wed Feb 14 21:16:43 2018 +0000
@@ -1,4 +1,13 @@
-/* Copyright (c) 2016 Aconno. All Rights Reserved.
+//plan of debugging and what the result was
+//what the problem is and how :lessons learned what was tried
+//your own development and knowledge
+//analysis report - working hard thinking throug the problems
+//less is more - essential information
+//what your thinkijg is what problems are and what u tried
+//point form 
+
+
+ /* Copyright (c) 2016 Aconno. All Rights Reserved.
  *
  * Licensees are granted free, non-transferable use of the information. NO
  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
@@ -9,17 +18,23 @@
 
 #include "mbed.h"
 #include "acd52832_bsp.h"
-#include "LSM9DS1_regs.h"
-#include "LSM9DS1_defVals.h"
+//#include "LSM9DS1_regs.h"
+//#include "LSM9DS1_defVals.h"
+#include "LSM9DS1.h"
 #include "GDEP015OC1.h"
+#include "aconno_i2c.h"
+//#include "main.h"
 
 // #define GYRO
 
-SPI spi(p3, NC, p4);
+SPI spi(p3, NC, p4); //keep this spi connection - for e paper display 
 GDEP015OC1 epd = GDEP015OC1(spi, p5, p6, p7, p8);
 
 // Initialize I2C protocol
 I2C mems(PIN_EXP_SDA, PIN_EXP_SCL);
+char memsI2CAddress = I2C_ADDRESS;
+LSM9DS1 mems(&i2c, memsI2CAddress);
+
 
 DigitalOut RED(PIN_LED_RED);
 DigitalOut GREEN(PIN_LED_GREEN);
@@ -27,6 +42,56 @@
 DigitalOut LEDD(PIN_LED);
 
 
+uint8_t LSM9DS1::enableAxes(Axis axis){
+    char ctrl1Copy;
+    i2c.readFromReg((char)CTRL_REG5_XL, &ctrl1Copy, 1);
+    ctrl1Copy |= axis;
+    i2c.writeToReg((char)CTRL_REG6_XL, &ctrl1Copy, 1);
+    return 0;
+}
+
+int16_t LSM9DS1::readXAxis(){
+    int16_t rawData;
+    char tempData;
+    // Make sure new data is ready
+    do{
+        i2c.readFromReg((char)STATUS_REG_0, &tempData, 1);
+    }while(!(tempData & 0x08));
+    do{
+        i2c.readFromReg((char)STATUS_REG_0, &tempData, 1);
+    }while(!(tempData & 0x80));
+    // Same data have been overwritten
+    
+    i2c.readFromReg((char)OUT_X_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_X_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+int16_t LSM9DS1::readYAxis(){
+    int16_t rawData;
+    char tempData;
+    i2c.readFromReg((char)OUT_Y_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_Y_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+int16_t LSM9DS1::readZAxis(){
+    int16_t rawData;
+    char tempData;
+    i2c.readFromReg((char)OUT_Z_H_XL, &tempData, 1);
+    rawData = (int8_t)tempData << 8;
+    i2c.readFromReg((char)OUT_Z_L_XL, &tempData, 1);
+    rawData |= (int8_t)tempData;
+    return rawData;
+}
+
+
+
+
 void check(bool success)
 {
     if(!success) {
@@ -46,44 +111,34 @@
 
 
 
-void start_mag()
+
+
+
+
+void start_acc()
 {
     char data[2];
     bool success;
-
-    data[0] = (char)CTRL_REG1_M;          // Target register
-    data[1] = (char)0x7C;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-
-    data[0] = (char)CTRL_REG2_M;          // Target register
-    data[1] = (char)0x60;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
+    
+    data[0] = (char)CTRL_REG5_XL;          // Target register
+    data[1] = (char)0x38;                 // Data to write
+    success = mems.write(TWI_AG_ADDR, data, 0x02,0);
     check(success);
-
-    data[0] = (char)CTRL_REG3_M;          // Target register
-    data[1] = (char)0x00;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
+    
+    data[0] = (char)CTRL_REG6_XL;          // Target register
+    data[1] = (char)0xC7;                 // Data to write
+    success = mems.write(TWI_AG_ADDR, data, 0x02,0);
     check(success);
-
-    data[0] = (char)CTRL_REG4_M;          // Target register
-    data[1] = (char)0x0C;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-
-    data[0] = (char)CTRL_REG5_M;          // Target register
-    data[1] = (char)0x00;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
+    
 }
 
-void read_mag(float *results){
+void read_acc(float *results){
     char results_[6];
     float res_final[3];
-    char out_x_l_m = OUT_X_L_M;
+    char out_x_l_xl = OUT_X_L_XL;
     
-    check (mems.write(TWI_MAG_ADDR, &out_x_l_m, 1, true));
-    check (mems.read(TWI_MAG_ADDR, results_, 6, 0));
+    check (mems.write(TWI_AG_ADDR, &out_x_l_xl, 1, true));
+    check (mems.read(TWI_AG_ADDR, results_, 6, 0));
     res_final[0] = ((results_[1]<<8) | results_[0]);
     res_final[1] = ((results_[3]<<8) | results_[2]);
     res_final[2] = ((results_[5]<<8) | results_[4]);
@@ -93,93 +148,13 @@
     *(results + 2) = res_final[2];
 }
 
-void start_acc()
-{
-    char data[2];
-    bool success;
-    
-    data[0] = (char)CTRL_REG5_XL;          // Target register
-    data[1] = (char)0x38;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-    data[0] = (char)CTRL_REG6_XL;          // Target register
-    data[1] = (char)0xC7;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-}
-
-void read_acc(float *results){
-    char results_[6];
-    float res_final[3];
-    char out_x_l_xl = OUT_X_L_XL;
-    
-    check (mems.write(TWI_MAG_ADDR, &out_x_l_xl, 1, true));
-    check (mems.read(TWI_MAG_ADDR, results_, 6, 0));
-    res_final[0] = ((results_[1]<<8) | results_[0]);
-    res_final[1] = ((results_[3]<<8) | results_[2]);
-    res_final[2] = ((results_[5]<<8) | results_[4]);
-    
-    *(results) = res_final[0];
-    *(results + 1) = res_final[1];
-    *(results + 2) = res_final[2];
-}
-
-void start_gyro(){
-    char data[2];
-    bool success;
-    
-    // If GYRO is defines (gyro enabled)
-    #ifdef GYRO
-        data[0] = (char)CTRL_REG6_XL;                  // Target register
-        data[1] = (char)0xC7 & (char)0x1F;             // Data to write
-        success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-        check(success);
-    #endif
-    
-    data[0] = (char)CTRL_REG1_G;          // Target register
-    data[1] = (char)0xC0;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-    data[0] = (char)CTRL_REG2_G;          // Target register
-    data[1] = (char)0x00;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-    data[0] = (char)CTRL_REG3_G;          // Target register
-    data[1] = (char)0x00;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-    data[0] = (char)CTRL_REG4;            // Target register
-    data[1] = (char)0x3A;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-    
-    data[0] = (char)ORIENT_CFG_G;          // Target register
-    data[1] = (char)0x00;                 // Data to write
-    success = mems.write(TWI_MAG_ADDR, data, 0x02,0);
-    check(success);
-}
-
-void read_gyro(float *results){
-    char results_[6];
-    float res_final[3];
-    char out_x_l_g = OUT_X_L_G;
-    
-    check (mems.write(TWI_MAG_ADDR, &out_x_l_g, 1, true));
-    check (mems.read(TWI_MAG_ADDR, results_, 6, 0));
-    res_final[0] = ((results_[1]<<8) | results_[0]);
-    res_final[1] = ((results_[3]<<8) | results_[2]);
-    res_final[2] = ((results_[5]<<8) | results_[4]);
-    
-    *(results) = res_final[0];
-    *(results + 1) = res_final[1];
-    *(results + 2) = res_final[2];
-}
-
+//////////////////////////////////////////////////////
+void read_bb(float *res) {
+    char res_[6];
+    float final_res[3];
+    char out_bb = out_xl_bb;
+}//char out_xl_bb
+/////////////////////////////////////////////////////////
 
 int main()
 {
@@ -190,30 +165,39 @@
     // Clear LEDs
     RED = 1;
     GREEN = 1;
+    //-----------------
+    
+    
     
     // Start acceleration sensor
     start_acc();
 
     while (1) {        
-        // Get data from mag sensor
+        // Get data from ag sensor
+        
         read_acc(results);
         
         if (*results != old_res) {
             // Write new value on display
             epd.empty();
+            ////////////////////
+            epd.writeString("Aconno Accelerometer Data:",10,50,0);
+            //////////////////
             epd.write();
             
-            // Write mag_x
+            
+            
+            // Write ag_x
             sprintf(buffer, "%+2.1f", *results);    //Create a string
             epd.writeString(buffer,85,70,0);                                       //Write new data to the buffer
             epd.write();
             
-            // Write mag_y
+            // Write ag_y
             sprintf(buffer, "%+2.1f", *(results+1));    //Create a string
             epd.writeString(buffer,85,80,0);                                       //Write new data to the buffer
             epd.write();
             
-            // Write mag_z
+            // Write ag_z
             sprintf(buffer, "%+2.1f", *(results+2));    //Create a string
             epd.writeString(buffer,85,90,0);                                       //Write new data to the buffer
             epd.write();
@@ -223,6 +207,9 @@
             wait (1);
             BLUE = 1;
             wait(1);
+            
+            
+        
         }
         LEDD = 0;
         wait(1);
@@ -230,5 +217,24 @@
         wait(1);
     }
 
+// from the bb:
+//while(1){
+  
+  //the functions are in the wrong class
+enableI2C();
+        mems.enableAxes(X_axis);    ////enable axis not woking????
+        mems.readXaxis();
+        mems.disableAxes(X_axis);
+        mems.enableAxes(Y_axis); 
+        mems.readYaxis();
+        mems.disableAxes(Y_axis);
+        mems.enableAxes(Z_axis); 
+        mems.readZaxis();
+        mems.disableAxes(Z_axis);
+        epd.writeString("BB Accelerometer Data:",10,90,0);
+        epd.write();
+        ///////////// write to epd
+        ///add in epd for each
 
-}
\ No newline at end of file
+ 
+//}
\ No newline at end of file