![](/media/cache/group/i2c_logo.png.50x50_q85.png)
I2C-bus switch with reset
Dependencies: mbed
Diff: PCA9546A.cpp
- Revision:
- 0:afc432dbba61
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCA9546A.cpp Wed Feb 04 06:04:27 2015 +0000 @@ -0,0 +1,23 @@ +#include "mbed.h" + +I2C i2c(p28,p27); // sda, scl +Serial pc(USBTX, USBRX); // tx, rx +char cmd[32]; +int i, j, k; +int sw; + +int main () +{ + i2c.frequency(100000); + pc.printf("PCA9546A Sample Program\r\n"); + + // PCA9546A + while(1) + { + pc.printf("選択チャネルは? 0 0 0 0 CH3 CH2 CH1 CH0 16進数で入力 \r\n"); + pc.scanf("%x", &sw); + pc.printf("CH3=%d, CH2=%d, CH1=%d, CH0=%d\r\n\r\n", (sw & 0x8)>>3, (sw & 0x4)>>2, (sw & 0x2)>>1, (sw & 0x1)); + cmd[0] = sw; // PCA9546 Cont Reg Ch1 enabled + i2c.write(0xe8, cmd, 1); // Send command string + } +}