Original

Fork of PCA9547 by Tedd OKANO

Committer:
okano
Date:
Tue Aug 12 22:40:35 2014 +0000
Revision:
7:995f209b8707
Parent:
4:3c0af4c37587
Child:
8:c716fb3ccb8d
sample of different I2C frequency for each devices

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 3:7e884a7805b1 1 /**
okano 3:7e884a7805b1 2 * PCA9547 library
okano 1:47f2cf4c6619 3 *
okano 3:7e884a7805b1 4 * @author Tedd OKANO
okano 3:7e884a7805b1 5 * @version 0.1
okano 3:7e884a7805b1 6 * @date July-2014
okano 3:7e884a7805b1 7 *
okano 3:7e884a7805b1 8 * PCA9547: an I2C bus multiplexer control library
okano 1:47f2cf4c6619 9 *
okano 3:7e884a7805b1 10 * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus.
okano 3:7e884a7805b1 11 * The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads.
okano 1:47f2cf4c6619 12 *
okano 4:3c0af4c37587 13 * For more information about PCA9547:
okano 3:7e884a7805b1 14 * http://www.nxp.com/documents/data_sheet/PCA9547.pdf
okano 3:7e884a7805b1 15 *
okano 1:47f2cf4c6619 16 */
okano 3:7e884a7805b1 17
okano 0:662ab6a5aa97 18 #include "PCA9547.h"
okano 0:662ab6a5aa97 19
okano 0:662ab6a5aa97 20 PCA9547::PCA9547( PinName sda, PinName scl, char i2c_address ) : i2c( sda, scl ), _i2c_addr( i2c_address )
okano 0:662ab6a5aa97 21 {
okano 0:662ab6a5aa97 22 // do nothing.
okano 0:662ab6a5aa97 23 // leave it in default state.
okano 7:995f209b8707 24
okano 7:995f209b8707 25 // FOR TEST PURPOSE
okano 7:995f209b8707 26 // THIS DEVICE USES DIFFERENT I2C FREQUENCY
okano 7:995f209b8707 27 i2c.frequency( 400 * 1000 );
okano 0:662ab6a5aa97 28 }
okano 0:662ab6a5aa97 29
okano 0:662ab6a5aa97 30 PCA9547::~PCA9547()
okano 0:662ab6a5aa97 31 {
okano 0:662ab6a5aa97 32
okano 0:662ab6a5aa97 33 }
okano 0:662ab6a5aa97 34
okano 0:662ab6a5aa97 35 void PCA9547::select( char channel )
okano 0:662ab6a5aa97 36 {
okano 0:662ab6a5aa97 37 char data = 0x08 | channel;
okano 0:662ab6a5aa97 38
okano 2:c3459a955c8c 39 i2c.write( _i2c_addr, &data, 1 );
okano 0:662ab6a5aa97 40 }
okano 2:c3459a955c8c 41
okano 2:c3459a955c8c 42 void PCA9547::disable( void )
okano 2:c3459a955c8c 43 {
okano 2:c3459a955c8c 44 char data = 0x00;
okano 2:c3459a955c8c 45
okano 2:c3459a955c8c 46 i2c.write( _i2c_addr, &data, 1 );
okano 2:c3459a955c8c 47 }