PCA9672 Library (I2C IO Expander Interface)
Simple output port toggling with PCA9672
#include "mbed.h" #include "PCA9672.h" PCA9672 ioxp(P0_10, P0_11); //I2C connected to PCA9672 in LPC800-MAX int main() { ioxp.frequency(100000); while (1) { ioxp.write(0xFF); wait(.250); ioxp.write(0x00); wait(.250); } }
Diff: PCA9672.cpp
- Revision:
- 0:27125e4cf941
diff -r 000000000000 -r 27125e4cf941 PCA9672.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCA9672.cpp Sat Sep 21 05:28:44 2013 +0000 @@ -0,0 +1,54 @@ +/* mbed PCA9672 I2C I/O Expander Library + * Copyright (c) 2013 viswesr + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "PCA9672.h" + +PCA9672::PCA9672(PinName sda, PinName scl) : _i2c(sda, scl) +{ + // Software Reset + _i2c.start(); + while(_i2c.write(0x00) !=1); + while(_i2c.write(0x06) !=1); + _i2c.stop(); + + /* Software reset is not required. But, gives an + indication if the selected I2C bus frequency works */ +} + +void PCA9672::frequency(int hz) +{ + _i2c.frequency(hz); +} + +void PCA9672::write(char value) +{ + _i2c.write(PCA9672_ADDR, &value, 1); +} + +int PCA9672::read(void) +{ + _i2c.read(PCA9672_ADDR | 0x01); +} + +PCA9672::~PCA9672() +{ + +} \ No newline at end of file