Device driver for TCA9554A, which is I2C GPIO expander IC.
Diff: tca9554a.cpp
- Revision:
- 2:0d772298e874
- Parent:
- 0:402147fa55f6
diff -r e02d9e33b9f3 -r 0d772298e874 tca9554a.cpp --- 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) {