This is sample code for interfacing ROHM's SENSORSHLD1-EVK-101 with Nordic Semiconductor's nRF51-DK Development Kit Host BTLE Board

Dependencies:   BLE_API mbed nRF51822

Fork of Nordic_UART_TEMPLATE_ROHM by ROHMUSDC

Code Example for ROHM Mutli-Sensor Shield on the Nordic Semiconductor nRF51-DK

This code was written to be used with the Nordic Semiconductor nRF51-DK.

This is the basic example code for interfacing ROHM's Multi-sensor Shield Board onto this board.

Additional information about the ROHM MultiSensor Shield Board can be found at the following link: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield

For code example for the ROHM SENSORSHLD0-EVK-101, please see the following link: https://developer.mbed.org/teams/ROHMUSDC/code/Nordic_UART_TEMPLATE_ROHM/

Operation

Ultimately, this code will initialize all the sensors on the Multi-sensor shield board and then poll the sensors. The sensor data will then be returned to the BTLE COM port link and will be view-able on any BTLE enabled phone that can connect to the Nordic UART Application.

Supported ROHM Sensor Devices

  • BDE0600G Temperature Sensor
  • BM1383GLV Pressure Sensor
  • BU52014 Hall Sensor
  • ML8511 UV Sensor
  • RPR-0521 ALS/PROX Sensor
  • BH1745NUC Color Sensor
  • KMX62 Accel/Mag Sensor
  • KX122 Accel Sensor
  • BM1422 MI Magnetometer Sensor
  • KXG03 Gyro/Accel Sensor

Updates from SHLD0 to SHLD1

  • Pressure Sensor Changes: Fixed Register Map Changes for BM1383AGLV, See Pressure Sensor Datasheet for more details - TEMP and PRES output switched
  • Added new #ifdef section for Magnetometer
  • Changed Gyro Device Address (7bit addr now 0x4F, not 0x4E)

Sensor Applicable Code Sections

  • Added a Section in "Main" to act as initialization
  • Added to the "Periodic Callback" to read sensor data and return to Phone/Host

Questions/Feedback

Please feel free to let us know any questions/feedback/comments/concerns on the ROHM shield implementation by contacting the following e-mail:

Revision:
8:2a19622864c2
Parent:
7:71046927a0e9
Child:
9:878e7fad5347
--- a/main.cpp	Fri Dec 18 00:19:01 2015 +0000
+++ b/main.cpp	Wed Jun 08 18:20:30 2016 +0000
@@ -21,19 +21,26 @@
  *  Description: This Applications interfaces ROHM's Multi-Sensor Shield Board with the Nordic nRF51-DK
  *  This Code supports the following sensor devices on the shield:
  *      > BDE0600G Temperature Sensor
- *      > BM1383GLV Pressure Sensor
+ *      > BM1383AGLV Pressure Sensor
  *      > BU52014 Hall Sensor
  *      > ML8511 UV Sensor
  *      > RPR-0521 ALS/PROX Sensor
  *      > BH1745NUC Color Sensor
  *      > KMX62 Accel/Mag Sensor
  *      > KX122 Accel Sensor
+ *      > BM1422GMV MI Magnetometer
  *      > KXG03 Gyro (Currently Unavailable as IC hasn't docked yet)
  *
  *  New Code: 
  *      Added Variable Initialization for utilizing ROHM Sensors
  *      Added a Section in "Main" to act as initialization
  *      Added to the "Periodic Callback" to read sensor data and return to Phone/Host
+ *
+ *  Updates from SHLD0 to SHLD1:
+ *      > Pressure Sensor Changes: Fixed Register Map Changes for BM1383AGLV 
+ *          (See Pressure Sensor Datasheet for more details - TEMP and PRES output switched)
+ *      > Added new #ifdef section for Magnetometer
+ *      > Changed Gyro Device Address (7bit addr now 0x4F, not 0x4E)
  *  
  *  Additional information about the ROHM MultiSensor Shield Board can be found at the following link:
  *      https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield
@@ -53,6 +60,7 @@
 #define Color               //BH1745, Color Sensor
 #define KX122               //KX122, Accelerometer Sensor
 #define Pressure            //BM1383, Barometric Pressure Sensor
+#define Magnetometer        //BM1422GMV, MI Magnetometer Sensor
 #define KXG03               //KXG03, Gyroscopic Sensor
 
 #include "mbed.h"
@@ -82,9 +90,8 @@
 DigitalIn   testButton(p20);    //Original
 //DigitalIn   testButton(p19);
 InterruptIn sw4Press(p20);      //Original
-//InterruptIn sw4Press(p19);  
+//InterruptIn sw4Press(p19);
 I2C         i2c(p30,p7);  //Original DK Kit
-//I2C         i2c(p26,p27);
 bool        RepStart = true;
 bool        NoRepStart = false;
 int         i = 1;
@@ -228,6 +235,22 @@
 float       BM1383_Deci;
 #endif
 
+#ifdef Magnetometer
+int         BM1422_addr_w = 0x1E;
+int         BM1422_addr_r = 0x1F;
+char        BM1422_Content_ReadData[6];
+
+char        BM1422_CNTL1_Init[2] = {0x1B, 0xC0};
+char        BM1422_CNTL4_HB_Init[2] = {0x5C, 0x00};
+char        BM1422_CNTL4_LB_Init[2] = {0x5D, 0x00};
+char        BM1422_CNTL3_Init[2] = {0x1D, 0x40};
+
+char        BM1422_Addr_ReadData = 0x10;
+short int   BM1422_MAG_X_RawOUT = 0;
+short int   BM1422_MAG_Y_RawOUT = 0;
+short int   BM1422_MAG_Z_RawOUT = 0;
+#endif
+
 #ifdef KXG03
 int         j = 11;
 int         t = 1;
@@ -242,8 +265,8 @@
 short int   aveZ3 = 0;
 float       ave22;
 float       ave33;
-int         KXG03_addr_w = 0x9C;   //write 
-int         KXG03_addr_r = 0x9D;   //read 
+int         KXG03_addr_w = 0x9E;   //write 
+int         KXG03_addr_r = 0x9F;   //read
 char        KXG03_STBY_REG[2] = {0x43, 0x00};
 char        KXG03_Content_ReadData[6];
 //char        KXG03_Content_Accel_ReadData[6];
@@ -590,11 +613,11 @@
             i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart);
             i2c.read(Press_addr_r, &Press_Content_ReadData[0], 6, NoRepStart);
             
-            BM1383_Temp_Out = (Press_Content_ReadData[0]<<8) | (Press_Content_ReadData[1]);
+            BM1383_Temp_Out = (Press_Content_ReadData[3]<<8) | (Press_Content_ReadData[4]);
             BM1383_Temp_Conv_Out = (float)BM1383_Temp_Out/32;
             
-            BM1383_Var  = (Press_Content_ReadData[2]<<3) | (Press_Content_ReadData[3] >> 5);
-            BM1383_Deci = ((Press_Content_ReadData[3] & 0x1f) << 6 | ((Press_Content_ReadData[4] >> 2)));
+            BM1383_Var  = (Press_Content_ReadData[0]<<3) | (Press_Content_ReadData[1] >> 5);
+            BM1383_Deci = ((Press_Content_ReadData[1] & 0x1f) << 6 | ((Press_Content_ReadData[2] >> 2)));
             BM1383_Deci = (float)BM1383_Deci* 0.00048828125;  //0.00048828125 = 2^-11
             BM1383_Pres_Conv_Out = (BM1383_Var + BM1383_Deci);   //question pending here...
             
@@ -613,7 +636,40 @@
         #endif  
         i++;
     }
-    else if(i == 9){
+    
+    else if (i == 9){
+        #ifdef Magnetometer
+        if (m_ble.getGapState().connected) {
+            //Read color Portion from the IC
+            i2c.write(BM1422_addr_w, &BM1422_Addr_ReadData, 1, RepStart);
+            i2c.read(BM1422_addr_r, &BM1422_Content_ReadData[0], 6, NoRepStart);
+            
+            BM1422_MAG_X_RawOUT = (BM1422_Content_ReadData[1]<<8) | (BM1422_Content_ReadData[0]);
+            BM1422_MAG_Y_RawOUT = (BM1422_Content_ReadData[3]<<8) | (BM1422_Content_ReadData[2]);
+            BM1422_MAG_Z_RawOUT = (BM1422_Content_ReadData[5]<<8) | (BM1422_Content_ReadData[4]);
+            
+            
+            len = snprintf((char*) buf, MAX_REPLY_LEN, "Mag Sensor:");
+            m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+            wait_ms(20);
+            
+            len = snprintf((char*) buf, MAX_REPLY_LEN, "  X_raw= %i", BM1422_MAG_X_RawOUT);
+            m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+            wait_ms(20);
+
+            len = snprintf((char*) buf, MAX_REPLY_LEN, "  Y_raw= %i", BM1422_MAG_Y_RawOUT);
+            m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+            wait_ms(20);
+
+            len = snprintf((char*) buf, MAX_REPLY_LEN, "  Z_raw= %i", BM1422_MAG_Z_RawOUT);
+            m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+            wait_ms(20);
+        }        
+        #endif  
+        i++;
+    }
+    
+    else if(i == 10){
         #ifdef KXG03
         if (m_ble.getGapState().connected) {
         i2c.write(KXG03_addr_w, &KXG03_Addr_ReadData, 1, RepStart);
@@ -826,6 +882,13 @@
     i2c.write(Press_addr_w, &Mode_Control[0], 2, false);
     #endif
     
+    #ifdef Magnetometer
+    i2c.write(BM1422_addr_w, &BM1422_CNTL1_Init[0], 2, false);
+    i2c.write(BM1422_addr_w, &BM1422_CNTL4_HB_Init[0], 2, false);
+    i2c.write(BM1422_addr_w, &BM1422_CNTL4_LB_Init[0], 2, false);
+    i2c.write(BM1422_addr_w, &BM1422_CNTL3_Init[0], 2, false);
+    #endif
+    
     #ifdef KXG03
     i2c.write(KXG03_addr_w, &KXG03_STBY_REG[0], 2, false);        
     #endif