PCF8574 I2C Portexpanders used to provide data, address and controlbus interface

Dependents:   mbed_bus

Committer:
wim
Date:
Sun Jan 25 17:50:03 2015 +0000
Revision:
0:12207c70f4ea
PCF8574 Bus Class. First release, converted into lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:12207c70f4ea 1 /* PCF8574_AddressBus - Use the PCF8574 I2C Port Extender for controlling the Address Bus
wim 0:12207c70f4ea 2 * Copyright (c) 2011 Wim Huiskamp
wim 0:12207c70f4ea 3 *
wim 0:12207c70f4ea 4 * Released under the MIT License: http://mbed.org/license/mit
wim 0:12207c70f4ea 5 *
wim 0:12207c70f4ea 6 * version 0.2 Initial Release
wim 0:12207c70f4ea 7 */
wim 0:12207c70f4ea 8 #include "mbed.h"
wim 0:12207c70f4ea 9 #include "PCF8574_AddressBus.h"
wim 0:12207c70f4ea 10
wim 0:12207c70f4ea 11 /** Create an PCF8574_AddressBus object connected to the specified I2C object and using the specified deviceAddress
wim 0:12207c70f4ea 12 *
wim 0:12207c70f4ea 13 * @param I2C &i2c the I2C port to connect to
wim 0:12207c70f4ea 14 * @param char deviceAddress the address of the PCF8574
wim 0:12207c70f4ea 15 */
wim 0:12207c70f4ea 16 PCF8574_AddressBus::PCF8574_AddressBus(I2C &i2c, char deviceAddress) : _i2c(i2c) {
wim 0:12207c70f4ea 17 _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
wim 0:12207c70f4ea 18 _readOpcode = deviceAddress | 0x01; // low order bit = 1 for read
wim 0:12207c70f4ea 19 _init();
wim 0:12207c70f4ea 20 }
wim 0:12207c70f4ea 21
wim 0:12207c70f4ea 22 /** Optimised AddressBus write operation.
wim 0:12207c70f4ea 23 * @param address the addressvalue to output on the bus
wim 0:12207c70f4ea 24 */
wim 0:12207c70f4ea 25 void PCF8574_AddressBus::write(char address) {
wim 0:12207c70f4ea 26 char data[1];
wim 0:12207c70f4ea 27
wim 0:12207c70f4ea 28 data[0] = address;
wim 0:12207c70f4ea 29 _i2c.write(_writeOpcode, data, 1); // Write addressvalue to bus
wim 0:12207c70f4ea 30 }
wim 0:12207c70f4ea 31
wim 0:12207c70f4ea 32
wim 0:12207c70f4ea 33 /** Init PCF8574_AddressBus
wim 0:12207c70f4ea 34 * @param
wim 0:12207c70f4ea 35 * @returns
wim 0:12207c70f4ea 36 */
wim 0:12207c70f4ea 37 void PCF8574_AddressBus::_init() {
wim 0:12207c70f4ea 38
wim 0:12207c70f4ea 39 write(0x00);
wim 0:12207c70f4ea 40 }