library for the motor driver
Dependents: 4180_final_project
Fork of libTCS34725 by
TCA9548.cpp@4:cc00e3842f1b, 2017-03-09 (annotated)
- Committer:
- mwilkens241
- Date:
- Thu Mar 09 18:42:41 2017 +0000
- Revision:
- 4:cc00e3842f1b
- Parent:
- TCS34725.cpp@3:afb107db7994
working mux
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 | 4:cc00e3842f1b | 3 | TCA9548::TCA9548() : i2c(SDA,SCL) {} |
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 | } |