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);
    }

}

Committer:
viswesr
Date:
Sat Sep 21 05:28:44 2013 +0000
Revision:
0:27125e4cf941
PCA9672 Library (I2C IO Expander Interface) : First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
viswesr 0:27125e4cf941 1 /* mbed PCA9672 I2C I/O Expander Library
viswesr 0:27125e4cf941 2 * Copyright (c) 2013 viswesr
viswesr 0:27125e4cf941 3 *
viswesr 0:27125e4cf941 4 * MIT License
viswesr 0:27125e4cf941 5 *
viswesr 0:27125e4cf941 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
viswesr 0:27125e4cf941 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
viswesr 0:27125e4cf941 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
viswesr 0:27125e4cf941 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
viswesr 0:27125e4cf941 10 * furnished to do so, subject to the following conditions:
viswesr 0:27125e4cf941 11 *
viswesr 0:27125e4cf941 12 * The above copyright notice and this permission notice shall be included in all copies or
viswesr 0:27125e4cf941 13 * substantial portions of the Software.
viswesr 0:27125e4cf941 14 *
viswesr 0:27125e4cf941 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
viswesr 0:27125e4cf941 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
viswesr 0:27125e4cf941 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
viswesr 0:27125e4cf941 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
viswesr 0:27125e4cf941 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
viswesr 0:27125e4cf941 20 */
viswesr 0:27125e4cf941 21
viswesr 0:27125e4cf941 22 #include "PCA9672.h"
viswesr 0:27125e4cf941 23
viswesr 0:27125e4cf941 24 PCA9672::PCA9672(PinName sda, PinName scl) : _i2c(sda, scl)
viswesr 0:27125e4cf941 25 {
viswesr 0:27125e4cf941 26 // Software Reset
viswesr 0:27125e4cf941 27 _i2c.start();
viswesr 0:27125e4cf941 28 while(_i2c.write(0x00) !=1);
viswesr 0:27125e4cf941 29 while(_i2c.write(0x06) !=1);
viswesr 0:27125e4cf941 30 _i2c.stop();
viswesr 0:27125e4cf941 31
viswesr 0:27125e4cf941 32 /* Software reset is not required. But, gives an
viswesr 0:27125e4cf941 33 indication if the selected I2C bus frequency works */
viswesr 0:27125e4cf941 34 }
viswesr 0:27125e4cf941 35
viswesr 0:27125e4cf941 36 void PCA9672::frequency(int hz)
viswesr 0:27125e4cf941 37 {
viswesr 0:27125e4cf941 38 _i2c.frequency(hz);
viswesr 0:27125e4cf941 39 }
viswesr 0:27125e4cf941 40
viswesr 0:27125e4cf941 41 void PCA9672::write(char value)
viswesr 0:27125e4cf941 42 {
viswesr 0:27125e4cf941 43 _i2c.write(PCA9672_ADDR, &value, 1);
viswesr 0:27125e4cf941 44 }
viswesr 0:27125e4cf941 45
viswesr 0:27125e4cf941 46 int PCA9672::read(void)
viswesr 0:27125e4cf941 47 {
viswesr 0:27125e4cf941 48 _i2c.read(PCA9672_ADDR | 0x01);
viswesr 0:27125e4cf941 49 }
viswesr 0:27125e4cf941 50
viswesr 0:27125e4cf941 51 PCA9672::~PCA9672()
viswesr 0:27125e4cf941 52 {
viswesr 0:27125e4cf941 53
viswesr 0:27125e4cf941 54 }