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

/media/uploads/okano/pca9547_connections.png

Information

For more information, please visit component page.

The PCA9547 is an octal bidirectional translating multiplexer controlled by the I2C-bus. The SCL/SDA upstream pair fans out to eight downstream pairs, or channels.

pca9547

Committer:
okano
Date:
Fri Apr 17 03:34:23 2015 +0000
Revision:
8:c716fb3ccb8d
Parent:
6:33ef755248e0
re-publishing to correct revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 1:47f2cf4c6619 1 /**
okano 1:47f2cf4c6619 2 * PCA9547 library
okano 1:47f2cf4c6619 3 *
okano 1:47f2cf4c6619 4 * @author Tedd OKANO
okano 6:33ef755248e0 5 * @version 0.2
okano 6:33ef755248e0 6 * @date Feb-2015
okano 1:47f2cf4c6619 7 *
okano 1:47f2cf4c6619 8 * PCA9547: an I2C bus multiplexer control library
okano 1:47f2cf4c6619 9 *
okano 1:47f2cf4c6619 10 * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus.
okano 1:47f2cf4c6619 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 1:47f2cf4c6619 14 * http://www.nxp.com/documents/data_sheet/PCA9547.pdf
okano 1:47f2cf4c6619 15 *
okano 1:47f2cf4c6619 16 */
okano 1:47f2cf4c6619 17
okano 0:662ab6a5aa97 18 #ifndef MBED_PCA9547_H
okano 0:662ab6a5aa97 19 #define MBED_PCA9547_H
okano 0:662ab6a5aa97 20
okano 0:662ab6a5aa97 21 #include "mbed.h"
okano 0:662ab6a5aa97 22
okano 1:47f2cf4c6619 23 /** PCA9547 class
okano 1:47f2cf4c6619 24 *
okano 1:47f2cf4c6619 25 * PCA9547: an I2C bus multiplexer control library
okano 1:47f2cf4c6619 26 *
okano 1:47f2cf4c6619 27 * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus.
okano 1:47f2cf4c6619 28 * The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads.
okano 1:47f2cf4c6619 29 *
okano 1:47f2cf4c6619 30 * For more informatioj about PCA9547:
okano 1:47f2cf4c6619 31 * http://www.nxp.com/documents/data_sheet/PCA9547.pdf
okano 1:47f2cf4c6619 32 *
okano 1:47f2cf4c6619 33 * Example:
okano 1:47f2cf4c6619 34 * @code
okano 1:47f2cf4c6619 35 * #include "mbed.h"
okano 1:47f2cf4c6619 36 * #include "LM75B.h"
okano 1:47f2cf4c6619 37 * #include "PCA9547.h"
okano 1:47f2cf4c6619 38 *
okano 5:f4f72501148a 39 * PCA9547 mux( p28, p27, 0xE0 );
okano 5:f4f72501148a 40 *
okano 1:47f2cf4c6619 41 * int main()
okano 1:47f2cf4c6619 42 * {
okano 1:47f2cf4c6619 43 * mux.select( 0 );
okano 1:47f2cf4c6619 44 *
okano 1:47f2cf4c6619 45 * LM75B tmp0( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled
okano 1:47f2cf4c6619 46 *
okano 1:47f2cf4c6619 47 * while(1) {
okano 1:47f2cf4c6619 48 * printf( "%.3f\r\n", tmp0.read() );
okano 1:47f2cf4c6619 49 * wait( 1.0 );
okano 1:47f2cf4c6619 50 * }
okano 1:47f2cf4c6619 51 * }
okano 1:47f2cf4c6619 52 * @endcode
okano 1:47f2cf4c6619 53 */
okano 1:47f2cf4c6619 54
okano 0:662ab6a5aa97 55 class PCA9547
okano 0:662ab6a5aa97 56 {
okano 0:662ab6a5aa97 57 public:
okano 1:47f2cf4c6619 58
okano 1:47f2cf4c6619 59 /** Create a PCA9547 instance connected to specified I2C pins with specified address
okano 1:47f2cf4c6619 60 *
okano 1:47f2cf4c6619 61 * @param sda I2C-bus SDA pin
okano 1:47f2cf4c6619 62 * @param scl I2C-bus SCL pin
okano 1:47f2cf4c6619 63 * @param i2c_address I2C-bus address (default: 0xE0)
okano 1:47f2cf4c6619 64 */
okano 0:662ab6a5aa97 65 PCA9547( PinName sda, PinName scl, char i2c_address = 0xE0 );
okano 0:662ab6a5aa97 66
okano 5:f4f72501148a 67 /** Create a PCA9546A instance connected to specified I2C pins with specified address
okano 5:f4f72501148a 68 *
okano 5:f4f72501148a 69 * @param &i2c_ I2C object (instance)
okano 5:f4f72501148a 70 * @param i2c_address I2C-bus address (default: 0xE0)
okano 5:f4f72501148a 71 */
okano 5:f4f72501148a 72 PCA9547( I2C &i2c_, char i2c_address = 0xE0 );
okano 5:f4f72501148a 73
okano 1:47f2cf4c6619 74 /** Destructor of PCA9547
okano 1:47f2cf4c6619 75 */
okano 0:662ab6a5aa97 76 ~PCA9547();
okano 0:662ab6a5aa97 77
okano 1:47f2cf4c6619 78 /** Channel select
okano 1:47f2cf4c6619 79 *
okano 2:c3459a955c8c 80 * Enable and select a channel
okano 1:47f2cf4c6619 81 *
okano 1:47f2cf4c6619 82 * @param channel channel number
okano 1:47f2cf4c6619 83 */
okano 0:662ab6a5aa97 84 void select( char channel );
okano 0:662ab6a5aa97 85
okano 2:c3459a955c8c 86 /** Disabling all channels
okano 2:c3459a955c8c 87 *
okano 2:c3459a955c8c 88 * Disable all channels
okano 2:c3459a955c8c 89 */
okano 2:c3459a955c8c 90 void disable( void );
okano 2:c3459a955c8c 91
okano 0:662ab6a5aa97 92 private:
okano 5:f4f72501148a 93 I2C *i2c_p;
okano 5:f4f72501148a 94 I2C &i2c;
okano 5:f4f72501148a 95 char i2c_addr;
okano 0:662ab6a5aa97 96 };
okano 0:662ab6a5aa97 97
okano 0:662ab6a5aa97 98 #endif // MBED_PCA9547_H