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
tca9548a.cpp@2:1107ee23873a, 2017-12-12 (annotated)
- Committer:
- sarahmarshy
- Date:
- Tue Dec 12 22:14:58 2017 +0000
- Revision:
- 2:1107ee23873a
- Parent:
- 0:5bd73cede544
Update address of control register. Add function for checking which I2C channel is set.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| akashvibhute | 0:5bd73cede544 | 1 | /** |
| akashvibhute | 0:5bd73cede544 | 2 | * TCA9548A library |
| akashvibhute | 0:5bd73cede544 | 3 | * |
| akashvibhute | 0:5bd73cede544 | 4 | * @author Akash Vibhute |
| akashvibhute | 0:5bd73cede544 | 5 | * @author < akash . roboticist [at] gmail . com > |
| akashvibhute | 0:5bd73cede544 | 6 | * @version 0.1 |
| akashvibhute | 0:5bd73cede544 | 7 | * @date May/24/2016 |
| akashvibhute | 0:5bd73cede544 | 8 | */ |
| akashvibhute | 0:5bd73cede544 | 9 | |
| akashvibhute | 0:5bd73cede544 | 10 | #include "tca9548a.h" |
| akashvibhute | 0:5bd73cede544 | 11 | |
| sarahmarshy | 2:1107ee23873a | 12 | TCA9548A::TCA9548A( PinName sda, PinName scl, uint8_t i2c_address, PinName resetPin) : i2c_(sda, scl), reset_pin(resetPin) |
| akashvibhute | 0:5bd73cede544 | 13 | { |
| akashvibhute | 0:5bd73cede544 | 14 | i2c_addr = i2c_address; |
| akashvibhute | 0:5bd73cede544 | 15 | } |
| akashvibhute | 0:5bd73cede544 | 16 | |
| akashvibhute | 0:5bd73cede544 | 17 | |
| akashvibhute | 0:5bd73cede544 | 18 | void TCA9548A::select( uint8_t channel ) |
| akashvibhute | 0:5bd73cede544 | 19 | { |
| akashvibhute | 0:5bd73cede544 | 20 | if(channel >= 8) return; |
| sarahmarshy | 2:1107ee23873a | 21 | char data[1]; |
| sarahmarshy | 2:1107ee23873a | 22 | data[0] = 1 << channel; |
| sarahmarshy | 2:1107ee23873a | 23 | int err = i2c_.write(0xE0, data, 1); |
| sarahmarshy | 2:1107ee23873a | 24 | } |
| sarahmarshy | 2:1107ee23873a | 25 | |
| sarahmarshy | 2:1107ee23873a | 26 | char TCA9548A::check_set_channel() |
| sarahmarshy | 2:1107ee23873a | 27 | { |
| sarahmarshy | 2:1107ee23873a | 28 | char data[1]; |
| sarahmarshy | 2:1107ee23873a | 29 | int err = i2c_.read(0xE1, data, 1); |
| sarahmarshy | 2:1107ee23873a | 30 | return data[0]; |
| akashvibhute | 0:5bd73cede544 | 31 | } |
| akashvibhute | 0:5bd73cede544 | 32 | |
| akashvibhute | 0:5bd73cede544 | 33 | void TCA9548A::reset( ) |
| akashvibhute | 0:5bd73cede544 | 34 | { |
| akashvibhute | 0:5bd73cede544 | 35 | reset_pin = 0; |
| akashvibhute | 0:5bd73cede544 | 36 | wait_ms(1); |
| akashvibhute | 0:5bd73cede544 | 37 | reset_pin = 1; |
| akashvibhute | 0:5bd73cede544 | 38 | } |
| akashvibhute | 0:5bd73cede544 | 39 |
