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 TCA9548A by
Revision 2:1107ee23873a, committed 2017-12-12
- Comitter:
- sarahmarshy
- Date:
- Tue Dec 12 22:14:58 2017 +0000
- Parent:
- 1:768491b5e55d
- Commit message:
- Update address of control register. Add function for checking which I2C channel is set.
Changed in this revision
tca9548a.cpp | Show annotated file Show diff for this revision Revisions of this file |
tca9548a.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/tca9548a.cpp Wed May 25 05:20:24 2016 +0000 +++ b/tca9548a.cpp Tue Dec 12 22:14:58 2017 +0000 @@ -9,21 +9,25 @@ #include "tca9548a.h" -TCA9548A::TCA9548A( PinName sda, PinName scl, uint8_t i2c_address, PinName resetPin, uint32_t hz ) : i2c_(sda, scl), reset_pin(resetPin) +TCA9548A::TCA9548A( PinName sda, PinName scl, uint8_t i2c_address, PinName resetPin) : i2c_(sda, scl), reset_pin(resetPin) { i2c_addr = i2c_address; - i2c_.frequency(hz); } void TCA9548A::select( uint8_t channel ) { - char data; //create temporary char buffer - if(channel >= 8) return; - - data = 1 << channel; - i2c_.write( i2c_addr << 1, &data, 1); + char data[1]; + data[0] = 1 << channel; + int err = i2c_.write(0xE0, data, 1); +} + +char TCA9548A::check_set_channel() +{ + char data[1]; + int err = i2c_.read(0xE1, data, 1); + return data[0]; } void TCA9548A::reset( )
--- a/tca9548a.h Wed May 25 05:20:24 2016 +0000 +++ b/tca9548a.h Tue Dec 12 22:14:58 2017 +0000 @@ -92,7 +92,7 @@ * @param reset TCA9546A reset pin (default: NC for simple pullup connected) * @param hz I2C bus frequency (default: 400kHz) */ - TCA9548A( PinName sda, PinName scl, uint8_t i2c_address = 0x70, PinName resetPin = NC, uint32_t hz = 400000 ); + TCA9548A( PinName sda, PinName scl, uint8_t i2c_address = 0x70, PinName resetPin = NC); /** Selecting a channel * @@ -101,6 +101,11 @@ * @param channel channel number */ void select(uint8_t channel); + + /** Check which channel is enabled + * + */ + char check_set_channel(); /** Reset TCA9546A *