Device driver for TCA9554A, which is I2C GPIO expander IC.

Dependents:   AKDP-RevD7_014

Files at this revision

API Documentation at this revision

Comitter:
coisme
Date:
Thu May 26 21:04:28 2016 +0000
Parent:
1:e02d9e33b9f3
Commit message:
Bug fixed. I2C write operation and bit calculation.

Changed in this revision

tca9554a.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/tca9554a.cpp	Thu May 05 17:55:38 2016 +0000
+++ b/tca9554a.cpp	Thu May 26 21:04:28 2016 +0000
@@ -18,7 +18,7 @@
     
     // Reads the register value.
     char val = 0;
-    if (connection->read((slaveAddress << 1), &val, LEN_ONE_BYTE) != 0) {
+    if (connection->read(((slaveAddress << 1) | 0x01), &val, LEN_ONE_BYTE) != 0) {
         return ERROR_I2C_READ;
     }
     
@@ -34,10 +34,10 @@
     buf[1] = (char)val;
     
     // Writes to the devices.
-    if (connection->write(slaveAddress, buf, LEN_TWO_BYTE) != 0) {
+    if (connection->write((slaveAddress << 1), buf, LEN_TWO_BYTE) != 0) {
         return ERROR_I2C_WRITE;
     }
-    
+        
     return SUCCESS;
 }
 
@@ -98,7 +98,7 @@
     }
     
     // Modify the specified bit by port.
-    buf = ((buf & (~port)) | val);
+    buf = ((buf & (~port) | (port * val)));
     
     // Write back the modified value to the register.
     if ((status=write(REG_ADDR_OUTPUT, buf)) != SUCCESS) {