Added support for banked registers
Dependents: Component_Test_Interface FalconWing MX_Spoile_Test Simple_Power_Distribution ... more
Diff: MCP23017.cpp
- Revision:
- 3:72da9cd002bd
- Parent:
- 1:e2edbd61f4d0
- Child:
- 4:868db61f5f4e
--- a/MCP23017.cpp Mon Dec 20 16:04:04 2010 +0000 +++ b/MCP23017.cpp Sun Aug 21 13:59:48 2011 +0000 @@ -5,6 +5,7 @@ * * version 0.2 Initial Release * version 0.3 Cleaned up +* version 0.4 Fixed problem with _read method */ #include "mbed.h" @@ -13,7 +14,7 @@ /** Create an MCP23017 object connected to the specified I2C object and using the specified deviceAddress * * @param I2C &i2c the I2C port to connect to -* @param char deviceAddress the address of the MSC23017 +* @param char deviceAddress the address of the MCP23017 */ MCP23017::MCP23017(I2C &i2c, char deviceAddress) : _i2c(i2c) { _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write @@ -23,24 +24,23 @@ /** Read from specified MCP23017 register * -* @param char address the internal registeraddress of the MSC23017 +* @param char address the internal registeraddress of the MCP23017 * @returns data from register */ char MCP23017::_read(char address) { char data[2]; - char result; data[0] = address; - _i2c.write(_writeOpcode, data, 1); // Select Register for reading - result = _i2c.read(_readOpcode); // Read from selected Register + _i2c.write(_writeOpcode, data, 1); // Select Register for reading + _i2c.read(_readOpcode, data, 1); // Read from selected Register - return result; + return data[0]; } /** Write to specified MCP23017 register * -* @param char address the internal registeraddress of the MSC23017 +* @param char address the internal registeraddress of the MCP23017 */ void MCP23017::_write(char address, char byte) { char data[2];