Adaptation for PCA9548 Nxp I2C switch
Fork of PCA9547 by
PCA9547.h@4:3c0af4c37587, 2014-07-01 (annotated)
- Committer:
- okano
- Date:
- Tue Jul 01 00:37:01 2014 +0000
- Revision:
- 4:3c0af4c37587
- Parent:
- 2:c3459a955c8c
- Child:
- 5:f4f72501148a
correction: typo in comment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 1:47f2cf4c6619 | 1 | /** |
okano | 1:47f2cf4c6619 | 2 | * PCA9547 library |
okano | 1:47f2cf4c6619 | 3 | * |
okano | 1:47f2cf4c6619 | 4 | * @author Tedd OKANO |
okano | 1:47f2cf4c6619 | 5 | * @version 0.1 |
okano | 1:47f2cf4c6619 | 6 | * @date July-2014 |
okano | 1:47f2cf4c6619 | 7 | * |
okano | 1:47f2cf4c6619 | 8 | * PCA9547: an I2C bus multiplexer control library |
okano | 1:47f2cf4c6619 | 9 | * |
okano | 1:47f2cf4c6619 | 10 | * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus. |
okano | 1:47f2cf4c6619 | 11 | * The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads. |
okano | 1:47f2cf4c6619 | 12 | * |
okano | 4:3c0af4c37587 | 13 | * For more information about PCA9547: |
okano | 1:47f2cf4c6619 | 14 | * http://www.nxp.com/documents/data_sheet/PCA9547.pdf |
okano | 1:47f2cf4c6619 | 15 | * |
okano | 1:47f2cf4c6619 | 16 | */ |
okano | 1:47f2cf4c6619 | 17 | |
okano | 0:662ab6a5aa97 | 18 | #ifndef MBED_PCA9547_H |
okano | 0:662ab6a5aa97 | 19 | #define MBED_PCA9547_H |
okano | 0:662ab6a5aa97 | 20 | |
okano | 0:662ab6a5aa97 | 21 | #include "mbed.h" |
okano | 0:662ab6a5aa97 | 22 | |
okano | 1:47f2cf4c6619 | 23 | /** PCA9547 class |
okano | 1:47f2cf4c6619 | 24 | * |
okano | 1:47f2cf4c6619 | 25 | * PCA9547: an I2C bus multiplexer control library |
okano | 1:47f2cf4c6619 | 26 | * |
okano | 1:47f2cf4c6619 | 27 | * PCA9547 is an I2C multiplexer which enables to select 1:8 multiplexed I2C bus. |
okano | 1:47f2cf4c6619 | 28 | * The multiplexer is useful for deviding I2C bus to avoiding slave address conflict and separating capacitive loads. |
okano | 1:47f2cf4c6619 | 29 | * |
okano | 1:47f2cf4c6619 | 30 | * For more informatioj about PCA9547: |
okano | 1:47f2cf4c6619 | 31 | * http://www.nxp.com/documents/data_sheet/PCA9547.pdf |
okano | 1:47f2cf4c6619 | 32 | * |
okano | 1:47f2cf4c6619 | 33 | * Example: |
okano | 1:47f2cf4c6619 | 34 | * @code |
okano | 1:47f2cf4c6619 | 35 | * #include "mbed.h" |
okano | 1:47f2cf4c6619 | 36 | * #include "LM75B.h" |
okano | 1:47f2cf4c6619 | 37 | * #include "PCA9547.h" |
okano | 1:47f2cf4c6619 | 38 | * |
okano | 1:47f2cf4c6619 | 39 | * int main() |
okano | 1:47f2cf4c6619 | 40 | * { |
okano | 1:47f2cf4c6619 | 41 | * PCA9547 mux( p28, p27, 0xE0 ); |
okano | 1:47f2cf4c6619 | 42 | * |
okano | 1:47f2cf4c6619 | 43 | * mux.select( 0 ); |
okano | 1:47f2cf4c6619 | 44 | * |
okano | 1:47f2cf4c6619 | 45 | * LM75B tmp0( p28, p27 ); // making instance after a branch of I2C bus (which is connecting the LM75B) enabled |
okano | 1:47f2cf4c6619 | 46 | * |
okano | 1:47f2cf4c6619 | 47 | * while(1) { |
okano | 1:47f2cf4c6619 | 48 | * printf( "%.3f\r\n", tmp0.read() ); |
okano | 1:47f2cf4c6619 | 49 | * wait( 1.0 ); |
okano | 1:47f2cf4c6619 | 50 | * } |
okano | 1:47f2cf4c6619 | 51 | * } |
okano | 1:47f2cf4c6619 | 52 | * @endcode |
okano | 1:47f2cf4c6619 | 53 | */ |
okano | 1:47f2cf4c6619 | 54 | |
okano | 0:662ab6a5aa97 | 55 | class PCA9547 |
okano | 0:662ab6a5aa97 | 56 | { |
okano | 0:662ab6a5aa97 | 57 | public: |
okano | 1:47f2cf4c6619 | 58 | |
okano | 1:47f2cf4c6619 | 59 | /** Create a PCA9547 instance connected to specified I2C pins with specified address |
okano | 1:47f2cf4c6619 | 60 | * |
okano | 1:47f2cf4c6619 | 61 | * @param sda I2C-bus SDA pin |
okano | 1:47f2cf4c6619 | 62 | * @param scl I2C-bus SCL pin |
okano | 1:47f2cf4c6619 | 63 | * @param i2c_address I2C-bus address (default: 0xE0) |
okano | 1:47f2cf4c6619 | 64 | */ |
okano | 0:662ab6a5aa97 | 65 | PCA9547( PinName sda, PinName scl, char i2c_address = 0xE0 ); |
okano | 0:662ab6a5aa97 | 66 | |
okano | 1:47f2cf4c6619 | 67 | /** Destructor of PCA9547 |
okano | 1:47f2cf4c6619 | 68 | */ |
okano | 0:662ab6a5aa97 | 69 | ~PCA9547(); |
okano | 0:662ab6a5aa97 | 70 | |
okano | 1:47f2cf4c6619 | 71 | /** Channel select |
okano | 1:47f2cf4c6619 | 72 | * |
okano | 2:c3459a955c8c | 73 | * Enable and select a channel |
okano | 1:47f2cf4c6619 | 74 | * |
okano | 1:47f2cf4c6619 | 75 | * @param channel channel number |
okano | 1:47f2cf4c6619 | 76 | */ |
okano | 0:662ab6a5aa97 | 77 | void select( char channel ); |
okano | 0:662ab6a5aa97 | 78 | |
okano | 2:c3459a955c8c | 79 | /** Disabling all channels |
okano | 2:c3459a955c8c | 80 | * |
okano | 2:c3459a955c8c | 81 | * Disable all channels |
okano | 2:c3459a955c8c | 82 | */ |
okano | 2:c3459a955c8c | 83 | void disable( void ); |
okano | 2:c3459a955c8c | 84 | |
okano | 0:662ab6a5aa97 | 85 | private: |
okano | 0:662ab6a5aa97 | 86 | I2C i2c; |
okano | 0:662ab6a5aa97 | 87 | char _i2c_addr; |
okano | 0:662ab6a5aa97 | 88 | }; |
okano | 0:662ab6a5aa97 | 89 | |
okano | 0:662ab6a5aa97 | 90 | #endif // MBED_PCA9547_H |