I2C sensor test program, derived from testI2C program. Simple test for FXOS8700CQ, HIH6130, MAG3110, MMA8451Q, MMA8452Q, MPL3115A2, MAX44000, MAX44005, MAX44008, MAX30101 included beside simple I2C read/write from testI2C.

Dependencies:   FXOS8700CQ HIH6130 IS31SE5000 MAG3110 MAX44000 MAX44005 MAX44008 MMA8451Q MMA8452Q MPL3115A2 VEML6040 VEML6075 mbed vt100 LM75B FXAS21002 MAX30101 VCNL4020 VCNL4100

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Wed Sep 13 05:23:18 2017 +0000
Parent:
16:84a856643eab
Child:
18:ee6f43cbfcc1
Commit message:
Bus scan now uses 2 byte read instead of 1 byte read, so that we don't have to worry about 2 byte only modules such as Vishay sensors

Changed in this revision

MSU.cpp Show annotated file Show diff for this revision Revisions of this file
MSU.h Show annotated file Show diff for this revision Revisions of this file
VCNL4020.lib Show annotated file Show diff for this revision Revisions of this file
VCNL4100.lib Show annotated file Show diff for this revision Revisions of this file
VEML6075.lib Show annotated file Show diff for this revision Revisions of this file
testSensor.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MSU.cpp	Tue Mar 28 04:43:23 2017 +0000
+++ b/MSU.cpp	Wed Sep 13 05:23:18 2017 +0000
@@ -17,6 +17,7 @@
 #include "FXAS21002.h"
 #include "S11059.h"
 #include "MAX30101.h"
+#include "VCNL4100.h"
 
 extern int test_loop ;
 extern int interval ; /* wait interval ms */
@@ -35,11 +36,13 @@
     {MSU_MAX30101_ADDRESS,   "MAX30101",   testMAX30101},
     {MSU_MPL3115A2_ADDRESS,  "MPL3115A2",  testMPL3115A2},
     {MSU_IS31SE5000_ADDRESS, "IS31SE5000", testIS31SE5000},
+//    {MSU_VCNL4020_ADDRESS,   "VCNL4020",   testVCNL4020"},
     {MSU_VEML6040A_ADDRESS,  "VEML6040A",  testVEML6040A},
     {MSU_VEML6075_ADDRESS,   "VEML6075",   testVEML6075},
     {MSU_LM75B_ADDRESS,      "LM75B",      testLM75B},
     {MSU_FXAS21002_ADDRESS,  "FXAS21002",  testFXAS21002},
     {MSU_S11059_ADDRESS,     "S11059",     testS11059},
+    {MSU_VCNL4100_I2C_ADDRESS, "VCNL4100", testVCNL4100},
     {0x00, 0, 0}
 } ;
 
@@ -451,6 +454,32 @@
     delete veml ;
 }
 
+void testVCNL4100(void)
+{
+    uint8_t psData = 0x00 ;
+    uint16_t alsData = 0x00 ;
+    VCNL4100 *vcnl4100 = 0 ;
+    
+    vcnl4100 = new VCNL4100(PIN_SDA, PIN_SCL, MSU_VCNL4100_I2C_ADDRESS) ;
+    
+    printf("=== test VCNL4100 for %s (%s)\n", BOARD_NAME, __DATE__) ;
+    printf("Proximity, Ambient Light\n") ;
+    
+    vcnl4100->setAlsConf(0x00) ;
+    vcnl4100->setPsConf12(0x0000) ;
+    vcnl4100->setSpo(0xA0) ;
+    wait(0.1) ;
+    
+    for (int i = 0 ; i < test_loop ; i++ ) {
+        psData = vcnl4100->getPsData() ;
+        alsData = vcnl4100->getAlsData() ;
+        printf("0x%02X, 0x%04X\n", psData, alsData) ;
+        wait(1);
+    }
+    delete vcnl4100 ;
+}
+
+
 void testS11059(void) 
 {
     uint16_t uR, uG, uB, uIR ;
--- a/MSU.h	Tue Mar 28 04:43:23 2017 +0000
+++ b/MSU.h	Wed Sep 13 05:23:18 2017 +0000
@@ -18,6 +18,7 @@
 #define MSU_FXAS21002_ADDRESS  0x20
 #define MSU_S11059_ADDRESS     0x2A
 #define MAX30101_I2C_ADDRESS   0x57
+#define MSU_VCNL4100_I2C_ADDRESS 0x60
 
 typedef void (*fptr)(void) ;
 
@@ -41,6 +42,7 @@
 void testIS31SE5000(void) ;
 void testVEML6040A(void) ;
 void testVEML6075(void) ;
+void testVCNL4100(void) ;
 void testLM75B(void) ;
 void testFXAS21002(void) ;
 void testS11059(void) ;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VCNL4020.lib	Wed Sep 13 05:23:18 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/MSS/code/VCNL4020/#4f4cdaf51fc2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VCNL4100.lib	Wed Sep 13 05:23:18 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/MSS/code/VCNL4100/#fbf1a72181fc
--- a/VEML6075.lib	Tue Mar 28 04:43:23 2017 +0000
+++ b/VEML6075.lib	Wed Sep 13 05:23:18 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/MSS/code/VEML6075/#8bc12629d49b
+http://developer.mbed.org/teams/MSS/code/VEML6075/#d0d23d5abf34
--- a/testSensor.cpp	Tue Mar 28 04:43:23 2017 +0000
+++ b/testSensor.cpp	Wed Sep 13 05:23:18 2017 +0000
@@ -32,6 +32,12 @@
 int test_loop = TEST_LOOP ;
 int interval = 100 ; /* ms wait interval */
 
+void doSWReset(void)
+{
+    printf("Software Reset\n") ;
+    SCB->AIRCR = 0x05FA0004 ;
+}
+
 void doClose(void)
 {
     if (i2c != 0) {
@@ -131,6 +137,7 @@
     printf("status              : print current status\n") ;
     printf("demo                : mulitple sensor demo\n") ;
     printf("help                : print this help\n") ;
+    printf("zzz                 : cause software reset\n") ;
     printf("\nPlease set local-echo to see what you are typing.\n") ;
     printf("\n") ; 
 }
@@ -170,12 +177,7 @@
 
     for (address = 1; address < 127 ; address++) {
         i2c = new DUMB_I2C(PIN_SDA, PIN_SCL, address) ;
-//        result = i2c->read(address, &data, 1) ;
-        if (address == 0x10) {
-            num_data = 2 ;
-        } else {
-            num_data = 1 ;
-        }
+        num_data = 2 ;
         result = i2c->read(0, data, num_data) ;
         if (result == 0) {
             printf("%02X : ", address) ;
@@ -269,6 +271,8 @@
         setTestInterval() ; break ;
     case 'b': case 'B': /* Bus Scan */
         doBusScan() ; break ;
+    case 'z': case 'Z': /* Software Reset */
+        doSWReset() ; break ;
     default:
         doHelp() ; break ;
     }