Hello program for PCA9546A component library. The PCA9546A is a quad bidirectional translating switch controlled via the I2C-bus. The SCL/SDA upstream pair fans out to four downstream pairs, or channels. Any individual SCx/SDx channel or combination of channels can be selected, determined by the contents of the programmable control register.
Dependencies: LM75B PCA9546A mbed
main.cpp@0:c88a1756cfd3, 2015-02-23 (annotated)
- Committer:
- okano
- Date:
- Mon Feb 23 06:07:56 2015 +0000
- Revision:
- 0:c88a1756cfd3
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:c88a1756cfd3 | 1 | /** |
okano | 0:c88a1756cfd3 | 2 | * PCA9546A library "Hello world" sample |
okano | 0:c88a1756cfd3 | 3 | * |
okano | 0:c88a1756cfd3 | 4 | * @author Tedd OKANO |
okano | 0:c88a1756cfd3 | 5 | * @version 0.1 |
okano | 0:c88a1756cfd3 | 6 | * @date Feb-2015 |
okano | 0:c88a1756cfd3 | 7 | * |
okano | 0:c88a1756cfd3 | 8 | * PCA9546A: an I2C bus switch control library |
okano | 0:c88a1756cfd3 | 9 | * |
okano | 0:c88a1756cfd3 | 10 | * The PCA9546A is a quad bidirectional translating switch controlled |
okano | 0:c88a1756cfd3 | 11 | * via the I2C-bus. The SCL/SDA upstream pair fans out to four downstream |
okano | 0:c88a1756cfd3 | 12 | * pairs, or channels. Any individual SCx/SDx channel or combination of |
okano | 0:c88a1756cfd3 | 13 | * channels can be selected, determined by the contents of the programmable |
okano | 0:c88a1756cfd3 | 14 | * control register. |
okano | 0:c88a1756cfd3 | 15 | * |
okano | 0:c88a1756cfd3 | 16 | * For more information about PCA9546A: |
okano | 0:c88a1756cfd3 | 17 | * http://www.nxp.com/documents/data_sheet/PCA9546A.pdf |
okano | 0:c88a1756cfd3 | 18 | * |
okano | 0:c88a1756cfd3 | 19 | */ |
okano | 0:c88a1756cfd3 | 20 | |
okano | 0:c88a1756cfd3 | 21 | #include "mbed.h" |
okano | 0:c88a1756cfd3 | 22 | #include "LM75B.h" |
okano | 0:c88a1756cfd3 | 23 | #include "PCA9546A.h" |
okano | 0:c88a1756cfd3 | 24 | |
okano | 0:c88a1756cfd3 | 25 | PCA9546A i2c_sw( p28, p27, 0xE0 ); |
okano | 0:c88a1756cfd3 | 26 | |
okano | 0:c88a1756cfd3 | 27 | int main() |
okano | 0:c88a1756cfd3 | 28 | { |
okano | 0:c88a1756cfd3 | 29 | // all PCA9546A's downstream ports are OFF after power-up and hardware-reset |
okano | 0:c88a1756cfd3 | 30 | |
okano | 0:c88a1756cfd3 | 31 | i2c_sw.on( 0 ); // turn-ON the channel 0 |
okano | 0:c88a1756cfd3 | 32 | |
okano | 0:c88a1756cfd3 | 33 | LM75B tmp0( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled |
okano | 0:c88a1756cfd3 | 34 | |
okano | 0:c88a1756cfd3 | 35 | i2c_sw.off( 0 ); // turn-OFF the channel 0 |
okano | 0:c88a1756cfd3 | 36 | i2c_sw.on( 1 ); // turn-ON the channel 1 |
okano | 0:c88a1756cfd3 | 37 | |
okano | 0:c88a1756cfd3 | 38 | LM75B tmp1( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled |
okano | 0:c88a1756cfd3 | 39 | |
okano | 0:c88a1756cfd3 | 40 | while(1) { |
okano | 0:c88a1756cfd3 | 41 | |
okano | 0:c88a1756cfd3 | 42 | i2c_sw.off( 1 ); // turn-OFF the channel 1 |
okano | 0:c88a1756cfd3 | 43 | i2c_sw.on( 0 ); // turn-ON the channel 0 |
okano | 0:c88a1756cfd3 | 44 | printf( "%.3f\r\n", tmp0.read() ); |
okano | 0:c88a1756cfd3 | 45 | |
okano | 0:c88a1756cfd3 | 46 | i2c_sw.off( 0 ); // turn-OFF the channel 0 |
okano | 0:c88a1756cfd3 | 47 | i2c_sw.on( 1 ); // turn-ON the channel 1 |
okano | 0:c88a1756cfd3 | 48 | printf( "%.3f\r\n", tmp1.read() ); |
okano | 0:c88a1756cfd3 | 49 | |
okano | 0:c88a1756cfd3 | 50 | wait( 1.0 ); |
okano | 0:c88a1756cfd3 | 51 | } |
okano | 0:c88a1756cfd3 | 52 | } |