Self test boot program for testing icarus sensors

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_UARTConsole by Bluetooth Low Energy

Revision:
10:3a24c970db40
Parent:
9:ed3636e1873f
Child:
11:70359785c2a7
--- a/ADXL362Sensor.cpp	Tue Jan 27 12:30:51 2015 +0000
+++ b/ADXL362Sensor.cpp	Tue Jan 27 13:25:37 2015 +0000
@@ -22,7 +22,7 @@
     //Device id is 0xAD
     //Device mems id is 0x1D
     //Part id is 0xF2
-    uint32_t sensorId = readRegister32(DEVID_AD);
+    uint32_t sensorId = readRegister32(ADXL362_DEVID_AD);
     
     if (sensorId >> 8 !=0xAD1DF2){
         errorResult[errors++] = ERROR_WRONG_DEVICE_ID;
@@ -30,7 +30,7 @@
     }
     
     //check status registry
-    uint8_t status  = readRegister(STATUS);
+    uint8_t status  = readRegister(ADXL362_STATUS);
     
     //indicate that SEU error was detetcted 
     if (status & (1 << 7)){
@@ -61,15 +61,15 @@
 // 1. Read acceleration data for the x-, y-, and z-axes.    
     refreshAcceleration12(&x12, &y12, &z12);    
 // 2. Assert self test by setting the ST bit in the SELF_TEST register, Address 0x2E.
-    writeRegister(SELF_TEST,0x01);
+    writeRegister(ADXL362_SELF_TEST,0x01);
 // 3. Wait 1/ODR for the output to settle to its new value.
-    
+    wait(1/ADXL362_ODR);
 // 4. Read acceleration data for the x-, y-, and z-axes.
     refreshAcceleration12(&test_x12, &test_y12, &test_z12);
 // 5. Compare to the values from Step 1, and convert the difference from LSB to mg by multiplying by the sensitivity. If the observed difference falls within the self test output change specification listed in Table 1, then the device passes self test and is deemed operational.
-    float reactionX = (x12-test_x12)* ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / SELF_TEST_SCALE_FACTOR;
-    float reactionY = (y12-test_y12)* ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / SELF_TEST_SCALE_FACTOR;
-    float reactionZ = (z12-test_z12)* ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / SELF_TEST_SCALE_FACTOR;
+    float reactionX = (x12-test_x12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR;
+    float reactionY = (y12-test_y12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR;
+    float reactionZ = (z12-test_z12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR;
     
     if (reactionX<0.450F || reactionX>0.710F ||
         reactionY<-0.710F || reactionY>-0.450F ||
@@ -79,7 +79,7 @@
     }
     
 // 6. Deassert self test by clearing the ST bit in the SELF_TEST register, Address 0x2E.
-    writeRegister(SELF_TEST,0x01);
+    writeRegister(ADXL362_SELF_TEST,0x01);
     
     return errors;
 }
@@ -89,8 +89,8 @@
     int16_t xyzVal[6] = {0, 0, 0, 0, 0, 0};
  
     *cs = DOWN;
-    spi->write(READ_REGISTER);
-    spi->write(DATA_12);
+    spi->write(ADXL362_READ_REGISTER);
+    spi->write(ADXL362_DATA_12);
  
     for (int i = 0; i < 6; i++) {
         xyzVal[i] = spi->write(0x00);
@@ -106,7 +106,7 @@
 uint32_t ADXL362Sensor::readRegister32( uint8_t reg){
     uint32_t val[4] = {0,0,0,0};
     *cs = DOWN;
-    spi->write(READ_REGISTER);
+    spi->write(ADXL362_READ_REGISTER);
     spi->write(reg);
     for (int i=0;i<4;i++){
         val[i] = spi->write(0x00);
@@ -119,7 +119,7 @@
 
 uint8_t ADXL362Sensor::readRegister( uint8_t reg){
     cs->write(DOWN);
-    spi->write(READ_REGISTER);
+    spi->write(ADXL362_READ_REGISTER);
     spi->write(reg);
     uint8_t val = spi->write(0x00);
     cs->write(UP);
@@ -128,7 +128,7 @@
 
 void ADXL362Sensor::writeRegister( uint8_t reg, uint8_t cmd ){
     cs->write(DOWN);
-    spi->write(WRITE_REGISTER);
+    spi->write(ADXL362_WRITE_REGISTER);
     spi->write(reg);
     spi->write(cmd);
     cs->write(UP);