PCA9547: an I2C bus multiplexer control library. PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus. The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads. For more information about PCA9547: http://www.nxp.com/documents/data_sheet/PCA9547.pdf
Dependents: pca9547_Hello m3Dpi
PCA9547.cpp
00001 /** 00002 * PCA9547 library 00003 * 00004 * @author Tedd OKANO 00005 * @version 0.2 00006 * @date Feb-2015 00007 * 00008 * PCA9547: an I2C bus multiplexer control library 00009 * 00010 * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus. 00011 * The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads. 00012 * 00013 * For more information about PCA9547: 00014 * http://www.nxp.com/documents/data_sheet/PCA9547.pdf 00015 * 00016 */ 00017 00018 #include "PCA9547.h" 00019 00020 PCA9547::PCA9547( PinName sda, PinName scl, char i2c_address ) 00021 : i2c_p( new I2C( sda, scl ) ), i2c( *i2c_p ), i2c_addr( i2c_address ) 00022 { 00023 // do nothing. 00024 // leave it in default state. 00025 } 00026 00027 PCA9547::PCA9547( I2C &i2c_, char i2c_address ) 00028 : i2c_p( NULL ), i2c( i2c_ ), i2c_addr( i2c_address ) 00029 { 00030 // do nothing. 00031 // leave it in default state. 00032 } 00033 00034 PCA9547::~PCA9547() 00035 { 00036 if ( NULL != i2c_p ) 00037 delete i2c_p; 00038 } 00039 00040 void PCA9547::select( char channel ) 00041 { 00042 char data = 0x08 | channel; 00043 00044 i2c.write( i2c_addr, &data, 1 ); 00045 } 00046 00047 void PCA9547::disable( void ) 00048 { 00049 char data = 0x00; 00050 00051 i2c.write( i2c_addr, &data, 1 ); 00052 }
Generated on Tue Jul 12 2022 19:04:32 by 1.7.2