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.
Fork of libTCS34725 by
TCA9548.cpp@6:79996efbdcb2, 2017-03-31 (annotated)
- Committer:
- mwilkens241
- Date:
- Fri Mar 31 15:49:30 2017 +0000
- Revision:
- 6:79996efbdcb2
- Parent:
- 4:cc00e3842f1b
nothin changed here, just committing
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mwilkens241 | 4:cc00e3842f1b | 1 | #include "TCA9548.h" |
| mwilkens241 | 0:4796574af790 | 2 | |
| mwilkens241 | 6:79996efbdcb2 | 3 | TCA9548::TCA9548() : i2c(PB_9,PB_8) {} |
| mwilkens241 | 4:cc00e3842f1b | 4 | TCA9548::TCA9548(PinName i2c_sda, PinName i2c_scl) : i2c(i2c_sda,i2c_scl) {} |
| mwilkens241 | 1:06c9bbbdb8b0 | 5 | |
| mwilkens241 | 4:cc00e3842f1b | 6 | void TCA9548::i2cWrite8(uint8_t addr, char data){ |
| mwilkens241 | 4:cc00e3842f1b | 7 | char packet[1] = {data & 0xFF}; |
| mwilkens241 | 4:cc00e3842f1b | 8 | i2c.write(addr,packet,1,false); //only write address and data ~ no reg |
| mwilkens241 | 2:cc2c0831a763 | 9 | wait(0.01); |
| mwilkens241 | 0:4796574af790 | 10 | } |
| mwilkens241 | 0:4796574af790 | 11 | |
| mwilkens241 | 4:cc00e3842f1b | 12 | bool TCA9548::init(uint8_t iCh){ |
| mwilkens241 | 1:06c9bbbdb8b0 | 13 | i2c.frequency(400000); |
| mwilkens241 | 4:cc00e3842f1b | 14 | channel = iCh; |
| mwilkens241 | 4:cc00e3842f1b | 15 | i2cWrite8(DEV_ADDR,(char)iCh); |
| mwilkens241 | 1:06c9bbbdb8b0 | 16 | return true; |
| mwilkens241 | 0:4796574af790 | 17 | } |
| mwilkens241 | 0:4796574af790 | 18 | |
| mwilkens241 | 4:cc00e3842f1b | 19 | bool TCA9548::init(){ |
| mwilkens241 | 4:cc00e3842f1b | 20 | i2c.frequency(400000); |
| mwilkens241 | 4:cc00e3842f1b | 21 | channel = 0; |
| mwilkens241 | 4:cc00e3842f1b | 22 | i2cWrite8(DEV_ADDR,0); |
| mwilkens241 | 4:cc00e3842f1b | 23 | wait(0.05); |
| mwilkens241 | 4:cc00e3842f1b | 24 | return true; |
| mwilkens241 | 1:06c9bbbdb8b0 | 25 | } |
| mwilkens241 | 1:06c9bbbdb8b0 | 26 | |
| mwilkens241 | 4:cc00e3842f1b | 27 | void TCA9548::ch(uint8_t newCh){ |
| mwilkens241 | 4:cc00e3842f1b | 28 | channel = newCh; |
| mwilkens241 | 4:cc00e3842f1b | 29 | i2cWrite8(DEV_ADDR,(char)newCh); |
| mwilkens241 | 4:cc00e3842f1b | 30 | wait(0.05); |
| mwilkens241 | 0:4796574af790 | 31 | } |
