MSS / MAX44000

Dependents:   test_MAX44000 testSensor PMK2022_Agriculture

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Thu Jul 07 01:06:25 2016 +0000
Parent:
0:c9c9e362ec57
Child:
2:93ed4e2fe7fd
Commit message:
the multi byte I2C read in getALS was not working, changed the read with a couple byte read fixed the problem.

Changed in this revision

MAX44000.cpp Show annotated file Show diff for this revision Revisions of this file
MAX44000.h Show annotated file Show diff for this revision Revisions of this file
--- a/MAX44000.cpp	Tue Dec 15 01:15:52 2015 +0000
+++ b/MAX44000.cpp	Thu Jul 07 01:06:25 2016 +0000
@@ -27,6 +27,12 @@
     
 MAX44000::MAX44000(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) {
     // activate the peripheral
+    uint8_t conf = 0 ;
+    conf = \
+          0x20 /* Use factory-programmed gains for green and IR channels. */
+        | 0x10 /* ALS and PROX are interleaved ontinuously. */
+        ;
+    setMainConfig(conf) ;
 }
 
 MAX44000::~MAX44000() { }
@@ -88,7 +94,9 @@
 void MAX44000::getALS(uint8_t *ofl, uint16_t *value) 
 {
     uint8_t data[2] ;
-    readRegs(REG_ADC_MSB, data, 2) ;
+//    readRegs(REG_ADC_MSB, data, 2) ;
+    readRegs(REG_ADC_MSB, data, 1) ;
+    readRegs(REG_ADC_LSB, &data[1], 1) ;
     *value = ((data[0] & 0x3F)<<8) | data[1] ;
     *ofl = (data[0] >> 6) & 0x01 ; // overflow
 }
--- a/MAX44000.h	Tue Dec 15 01:15:52 2015 +0000
+++ b/MAX44000.h	Thu Jul 07 01:06:25 2016 +0000
@@ -31,7 +31,37 @@
   */
 
 void getIntStatus(uint8_t *data) ;
+/**
+ * Get Main Configuration
+ *
+ * @param *conf uint8_t pointer to receive the 8bit register value.
+ *
+ * Bit[7:6] : (reserved)
+ * Bit[5]   : TRIM 
+ *   0: Use bytes written to TRIM_GAIN_GREEN[7:0] and TRIM_GAIN_IR[7:0] registers
+ *      to set the fine-trim gain of the green and IR gain channels.
+ *   1: Use factory-programmed gains for green and IR channels.
+ *      Ignore bytes written to TRIM_GAIN_GEEN[7:0] and TRIM_GAIN_IR[7:0] registers.
+ * Bit[4:2] : mode
+ *   000: Shutdown : Analog circuits are shut down, but the digital register retains values.
+ *   001: ALS G-IR : Standard ALS mode stores the difference between green and infrared channel readings.
+ *                   Proximity channel operation and updates are disabled.
+ *   010: ALS G    : ALS green channel only. Proximity channel operation and updates are disabled.
+ *   011: ALS IR   : Infrared channel only. Proximity channel operation and updates are disabled.
+ *   100: ALS/PROX : ALS and PROX are interleaved continuously.
+ *   101: PROX Only : PROX only continuously. ALS channel operation and updates are disabled.
+ *   110: (reserved)
+ *   111: (reserved)
+ * Bit[1]   : PRXINTE
+ * Bit[0]   : ALSINTE
+ */
 void getMainConfig(uint8_t *conf) ;
+/**
+ * Set Mein Configuration
+ *
+ * @param conf uint8_t to specify the 8bit register value.
+ * For the meanings of each bits, please refer to setMainConfig() description.
+ */
 void setMainConfig(uint8_t newConf) ;
 void getRxConfig(uint8_t *conf) ;
 void setRxConfig(uint8_t newConf) ;