Kazuaki Hongu / ADS1100
Revision:
3:7c8d1aa80a9d
Parent:
2:7ee26d7e2997
Child:
4:25de15d742ba
--- a/ADS1100.cpp	Wed Jun 20 07:05:53 2018 +0000
+++ b/ADS1100.cpp	Mon Jul 02 13:25:18 2018 +0000
@@ -15,26 +15,49 @@
 }
 
 void ADS1100::init(char addr) {
-    address = ADS1100_ADDR << 3 + addr; // make address
-    
+    address = ADS1100_ADDR + (addr << 1); // make address
     config.bit.ST=0; // must be 0
     config.bit.RE=0; // must be 0
     config.bit.SC=0; // continuous mode
     config.bit.DR=3; // 8SPS
-    config.bit.PGA=0; // No GAIN
+    config.bit.PGA=1; // 2倍 GAIN
     
     buf[0] = config.UC;
     
     _i2c.write(address, buf, 1);
 }
 
-uint16_t ADS1100::get()
-{
+void ADS1100::init() {
+    config.bit.ST=0; // must be 0
+    config.bit.RE=0; // must be 0
+    config.bit.SC=0; // continuous mode
+    config.bit.DR=3; // 8SPS
+    config.bit.PGA=1; // 2倍 GAIN   
+    
+    buf[0] = config.UC; 
+    
+    _i2c.write(address, buf, 1);
+}
+
+short ADS1100::get() {
 
     _i2c.read(address , buf, 3);
 
-    result.byte.UB=buf[0];
-    result.byte.LB=buf[1];
+    result.byte.UB=buf[1];
+    result.byte.LB=buf[0];
     config.UC=buf[2];
+    if (config.UC == 0b10001100) {
+        init();
+    }
     return result.S; // 16bit
-}
\ No newline at end of file
+}
+
+//char ADS1100::get() {
+//    _i2c.read(address , buf, 3);
+//
+//    result.byte.UB=buf[1];
+//    result.byte.LB=buf[0];
+//    config.UC=buf[2];
+//    
+//    return config.UC;
+//}
\ No newline at end of file