![](/media/cache/group/i2c_logo.png.50x50_q85.png)
I2C-bus switch with reset
Dependencies: mbed
PCA9546A.cpp@0:afc432dbba61, 2015-02-04 (annotated)
- Committer:
- wataaki
- Date:
- Wed Feb 04 06:04:27 2015 +0000
- Revision:
- 0:afc432dbba61
Initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wataaki | 0:afc432dbba61 | 1 | #include "mbed.h" |
wataaki | 0:afc432dbba61 | 2 | |
wataaki | 0:afc432dbba61 | 3 | I2C i2c(p28,p27); // sda, scl |
wataaki | 0:afc432dbba61 | 4 | Serial pc(USBTX, USBRX); // tx, rx |
wataaki | 0:afc432dbba61 | 5 | char cmd[32]; |
wataaki | 0:afc432dbba61 | 6 | int i, j, k; |
wataaki | 0:afc432dbba61 | 7 | int sw; |
wataaki | 0:afc432dbba61 | 8 | |
wataaki | 0:afc432dbba61 | 9 | int main () |
wataaki | 0:afc432dbba61 | 10 | { |
wataaki | 0:afc432dbba61 | 11 | i2c.frequency(100000); |
wataaki | 0:afc432dbba61 | 12 | pc.printf("PCA9546A Sample Program\r\n"); |
wataaki | 0:afc432dbba61 | 13 | |
wataaki | 0:afc432dbba61 | 14 | // PCA9546A |
wataaki | 0:afc432dbba61 | 15 | while(1) |
wataaki | 0:afc432dbba61 | 16 | { |
wataaki | 0:afc432dbba61 | 17 | pc.printf("選択チャネルは? 0 0 0 0 CH3 CH2 CH1 CH0 16進数で入力 \r\n"); |
wataaki | 0:afc432dbba61 | 18 | pc.scanf("%x", &sw); |
wataaki | 0:afc432dbba61 | 19 | 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)); |
wataaki | 0:afc432dbba61 | 20 | cmd[0] = sw; // PCA9546 Cont Reg Ch1 enabled |
wataaki | 0:afc432dbba61 | 21 | i2c.write(0xe8, cmd, 1); // Send command string |
wataaki | 0:afc432dbba61 | 22 | } |
wataaki | 0:afc432dbba61 | 23 | } |