KX022 Accelerometer library

Dependents:   LazuriteGraph_Hello KX022_Hello GR-PEACH_IoT_Platform_HTTP_sample

Revision:
3:e2d1659fe67e
Parent:
0:e642dd732c4b
--- a/KX022.cpp	Wed Mar 23 03:32:14 2016 +0000
+++ b/KX022.cpp	Wed Sep 14 09:16:41 2016 +0000
@@ -49,10 +49,11 @@
     unsigned char buf;
     unsigned char reg[2];
 
+    DEBUG_PRINT("KX022 init started\n\r");
     readRegs(KX022_WHO_AM_I, &buf, sizeof(buf));
     if (buf != KX022_WAI_VAL) {
-        DEBUG_PRINT("KX022 initialization error. (%d)\n", buf);
-        return;
+        DEBUG_PRINT("KX022 initialization error. (WAI %d, not %d)\n\r", buf, KX022_WAI_VAL);
+        DEBUG_PRINT("Trying to config anyway, in case there is some compatible sensor connected.\n\r");
     }
 
     reg[0] = KX022_CNTL1;
@@ -110,9 +111,14 @@
 
 void KX022::readRegs(int addr, uint8_t * data, int len)
 {
+    int read_nok;
     char t[1] = {addr};
+    
     m_i2c.write(m_addr, t, 1, true);
-    m_i2c.read(m_addr, (char *)data, len);
+    read_nok = m_i2c.read(m_addr, (char *)data, len);
+    if (read_nok){
+        DEBUG_PRINT("Read fail\n\r");        
+        }
 }
 
 void KX022::writeRegs(uint8_t * data, int len)