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.h
00001 /** TCA9548A library 00002 * 00003 * @author Akash Vibhute 00004 * @author < akash . roboticist [at] gmail . com > 00005 * @version 0.1 00006 * @date May/24/2016 00007 * 00008 * @section LICENSE 00009 * 00010 * Copyright (c) 2015 Akash Vibhute 00011 * 00012 * Licensed under the Apache License, Version 2.0 (the "License"); 00013 * you may not use this file except in compliance with the License. 00014 * You may obtain a copy of the License at 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 * 00023 * The above copyright notice and this permission notice shall be included in 00024 * all copies or substantial portions of the Software. 00025 * 00026 * 00027 */ 00028 00029 #ifndef TCA9548A_H 00030 #define TCA9548A_H 00031 00032 #include "mbed.h" 00033 00034 /** TCA9548A class 00035 * 00036 * @section DESCRIPTION 00037 * TCA9548A: Low-Voltage 8-Channel I2C Switch With Reset 00038 * The TCA9548A device has eight bidirectional translating switches that can be 00039 * controlled through the I2C bus. The SCL/SDA upstream pair fans out to eight 00040 * downstream pairs, or channels. Any individual SCn/SDn channel or combination 00041 * of channels can be selected, determined by the contents of the programmable 00042 * control register. 00043 * 00044 * The TCA9548A has a user 8 selectable address in the range 0x70 thru 0x77 (7-bit), 00045 * based on the configuration of Addr pins (A0, A1, A2). Default address is 0x70 for 00046 * A0:A2 pull down. 00047 * 00048 * Datasheet for TCA9548A can be found at: 00049 * http://www.ti.com/lit/ds/symlink/tca9548a.pdf 00050 * 00051 * Example: 00052 * @code 00053 * #include "mbed.h" 00054 * #include "LM75B.h" 00055 * #include "TCA9548A.h" 00056 * 00057 * TCA9548A i2c_sw(I2C_SDA, I2C_SCL); //default address 0x70 applied 00058 * 00059 * int main() 00060 * { 00061 * // By default TCA9548A performs a power on reset and all downstream ports are deselected 00062 * 00063 * i2c_sw.select(0); // select the channel 0 00064 * LM75B tmp0(I2C_SDA, I2C_SCL); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled 00065 * 00066 * i2c_sw.select(1); // select the channel 1 00067 * LM75B tmp1(I2C_SDA, I2C_SCL); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled 00068 * 00069 * while(1) { 00070 * 00071 * i2c_sw.select(0); // select the channel 0 00072 * printf( "%.3f\r\n", tmp0.read() ); 00073 * 00074 * i2c_sw.select(1); // select the channel 1 00075 * printf( "%.3f\r\n", tmp1.read() ); 00076 * 00077 * wait( 1.0 ); 00078 * } 00079 * } 00080 * @endcode 00081 */ 00082 00083 class TCA9548A 00084 { 00085 public: 00086 00087 /** Create a TCA9546A instance connected to specified I2C pins with specified address 00088 * 00089 * @param sda I2C-bus SDA pin 00090 * @param scl I2C-bus SCL pin 00091 * @param i2c_address I2C-bus address (default: 0x70) 00092 * @param reset TCA9546A reset pin (default: NC for simple pullup connected) 00093 * @param hz I2C bus frequency (default: 400kHz) 00094 */ 00095 TCA9548A( PinName sda, PinName scl, uint8_t i2c_address = 0x70, PinName resetPin = NC); 00096 00097 /** Selecting a channel 00098 * 00099 * Switch to commended downstream I2C channel 00100 * 00101 * @param channel channel number 00102 */ 00103 void select(uint8_t channel); 00104 00105 /** Check which channel is enabled 00106 * 00107 */ 00108 char check_set_channel(); 00109 00110 /** Reset TCA9546A 00111 * 00112 * Reset switch 00113 */ 00114 void reset(); 00115 00116 00117 private: 00118 I2C i2c_; 00119 DigitalOut reset_pin; 00120 uint8_t i2c_addr; 00121 00122 }; 00123 00124 #endif // TCA9548A_H
Generated on Tue Jul 12 2022 22:50:20 by
1.7.2
