Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PCA9546A.h
00001 /** 00002 * PCA9546A library 00003 * 00004 * @author Tedd OKANO 00005 * @version 0.1 00006 * @date Feb-2015 00007 * 00008 * PCA9546A: an I2C bus switch control library 00009 * 00010 * The PCA9546A is a quad bidirectional translating switch controlled 00011 * via the I2C-bus. The SCL/SDA upstream pair fans out to four downstream 00012 * pairs, or channels. Any individual SCx/SDx channel or combination of 00013 * channels can be selected, determined by the contents of the programmable 00014 * control register. 00015 * 00016 * For more information about PCA9546A: 00017 * http://www.nxp.com/documents/data_sheet/PCA9546A.pdf 00018 * 00019 */ 00020 00021 #ifndef MBED_PCA9546A_H 00022 #define MBED_PCA9546A_H 00023 00024 #include "mbed.h" 00025 00026 /** PCA9546A class 00027 * 00028 * PCA9546A: an I2C bus switch control library 00029 * 00030 * The PCA9546A is a quad bidirectional translating switch controlled 00031 * via the I2C-bus. The SCL/SDA upstream pair fans out to four downstream 00032 * pairs, or channels. Any individual SCx/SDx channel or combination of 00033 * channels can be selected, determined by the contents of the programmable 00034 * control register. 00035 * 00036 * For more information about PCA9546A: 00037 * http://www.nxp.com/documents/data_sheet/PCA9546A.pdf 00038 * 00039 * Example: 00040 * @code 00041 * #include "mbed.h" 00042 * #include "LM75B.h" 00043 * #include "PCA9546A.h" 00044 * 00045 * PCA9546A i2c_sw( p28, p27, 0xE0 ); 00046 * 00047 * int main() 00048 * { 00049 * // all PCA9546A's downstream ports are OFF after power-up and hardware-reset 00050 * 00051 * i2c_sw.on( 0 ); // turn-ON the channel 0 00052 * 00053 * LM75B tmp0( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled 00054 * 00055 * i2c_sw.off( 0 ); // turn-OFF the channel 0 00056 * i2c_sw.on( 1 ); // turn-ON the channel 1 00057 * 00058 * LM75B tmp1( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled 00059 * 00060 * while(1) { 00061 * 00062 * i2c_sw.off( 1 ); // turn-OFF the channel 1 00063 * i2c_sw.on( 0 ); // turn-ON the channel 0 00064 * printf( "%.3f\r\n", tmp0.read() ); 00065 * 00066 * i2c_sw.off( 0 ); // turn-OFF the channel 0 00067 * i2c_sw.on( 1 ); // turn-ON the channel 1 00068 * printf( "%.3f\r\n", tmp1.read() ); 00069 * 00070 * wait( 1.0 ); 00071 * } 00072 * } 00073 * @endcode 00074 */ 00075 00076 class PCA9546A 00077 { 00078 public: 00079 00080 /** Create a PCA9546A instance connected to specified I2C pins with specified address 00081 * 00082 * @param sda I2C-bus SDA pin 00083 * @param scl I2C-bus SCL pin 00084 * @param i2c_address I2C-bus address (default: 0xE0) 00085 */ 00086 PCA9546A( PinName sda, PinName scl, char i2c_address = 0xE0 ); 00087 00088 /** Create a PCA9546A instance connected to specified I2C pins with specified address 00089 * 00090 * @param &i2c_ I2C object (instance) 00091 * @param i2c_address I2C-bus address (default: 0xE0) 00092 */ 00093 PCA9546A( I2C &i2c_, char i2c_address = 0xE0 ); 00094 00095 /** Destructor of PCA9546A 00096 */ 00097 ~PCA9546A(); 00098 00099 /** Turning-ON a channel 00100 * 00101 * Switching a channel ON 00102 * 00103 * @param channel channel number 00104 */ 00105 void on( char channel ); 00106 00107 /** Turning-OFF a channel 00108 * 00109 * Switching a channel OFF 00110 * 00111 * @param channel channel number 00112 */ 00113 void off( char channel ); 00114 00115 /** Switching by bit pattern 00116 * 00117 * Switch setting by bit pattern. 00118 * Set '1' for ON, set '0' for OFF 00119 * LSB is channel 0. Channels 1, 2 and 3 are mapped in shifted position from LSB 00120 * 00121 * @param pattern ON/OFF bit pattern for channels 00122 */ 00123 void bitpattern( char pattern ); 00124 00125 private: 00126 I2C *i2c_p; 00127 I2C &i2c; 00128 char i2c_addr; 00129 char enable_pattern; 00130 }; 00131 00132 #endif // MBED_PCA9546A_H
Generated on Wed Jul 13 2022 09:41:37 by
1.7.2
PCA9546A: 4-channel I2C switch