Jurica Resetar / aconno_I2C

Dependents:   acd52832_Humidity_Temp_Example BB acnSensa_LIS aconnoCellularGnss ... more

Files at this revision

API Documentation at this revision

Comitter:
jurica238814
Date:
Fri Sep 22 16:48:28 2017 +0000
Parent:
0:bfefd65ef71d
Child:
2:3c0eab894a4b
Commit message:
Send command and readBus methods added.

Changed in this revision

aconno_i2c.cpp Show annotated file Show diff for this revision Revisions of this file
aconno_i2c.h Show annotated file Show diff for this revision Revisions of this file
--- a/aconno_i2c.cpp	Fri Sep 22 12:46:17 2017 +0000
+++ b/aconno_i2c.cpp	Fri Sep 22 16:48:28 2017 +0000
@@ -32,6 +32,17 @@
     return success;
 }
 
+/* 
+ *  This method is used with sendCommand(char *command, uint8_t len) method when delay between command
+ *  and response from the slave is required
+ */
+uint8_t aconno_i2c::readBus(char *dataBuffer, int len){
+    uint8_t success;    /* 0 on success (ack), non-0 on failure (nack) */
+    
+    success = read(i2cAddress | 0x01, dataBuffer, len);     // R/W bit is set high for a read command
+    return success;
+}
+
 /*
  *  This method is used to send commands to I2C Device. 
  *  Ex. send 2B command to Si7006 to get Device ID.
@@ -44,4 +55,10 @@
     return success;
 }
 
+uint8_t aconno_i2c::sendCommand(char *command, uint8_t len){
+    uint8_t success;    /* 0 on success (ack), non-0 on failure (nack) */
+    
+    success = write(i2cAddress & 0xFE, command, len);
+    return success;
+}
 
--- a/aconno_i2c.h	Fri Sep 22 12:46:17 2017 +0000
+++ b/aconno_i2c.h	Fri Sep 22 16:48:28 2017 +0000
@@ -18,6 +18,8 @@
         uint8_t writeToReg(char regAddress, char *data, int len);
         uint8_t readFromReg(char regAddress, char *dataBuffer, int len);
         uint8_t sendCommand(char *command, uint8_t len, char *response, uint8_t responseLen);
+        uint8_t sendCommand(char *command, uint8_t len);
+        uint8_t readBus(char *dataBuffer, int len);
     private:
         uint8_t i2cAddress;
 };