Simple MCP23017 I2C 16bit IO expander IC
MCP23017 Class Reference
#include <MCP23017.h>
Public Member Functions | |
MCP23017 (I2C &_i2c, char _addr) | |
Constructor. | |
void | init (void) |
Software Reset. | |
void | setConfig (char _value) |
Configure MCP23017 Write IOCON register See MCP23017 datasheet p18 http://ww1.microchip.com/downloads/jp/DeviceDoc/21952b.pdf. | |
void | setDirrection (char _port, char _value) |
Set I/O dirrection. | |
void | setPullUp (char _port, char _value) |
Set pullup. | |
void | setInputPolarity (char _port, char _value) |
Set Input Polarity. | |
void | write (char _port, char _value) |
Write GPIO. | |
char | read (char _port) |
Read GPIO. |
Detailed Description
MCP23017 class.
Allow access MCP23017 I2C 16bit io expander IC But this library can not controll interrupt functions
Example:
#include "mbed.h" #include "MCP23017.h" I2C i2c(dp5, dp27); // LPC1114 MCP23017::MCP23017 io(&i2c,MCP23017_DEFAULT_ADDR); int main(void) { i2c.frequency(400000); // software reset io.init(); io.setDirrection(MCP23017_PORTA, 0xFF); // set all of the PORTA pins to input io.setDirrection(MCP23017_PORTB, 0x00); // set all of the PORTB pins to output io.setPullUp(MCP23017_PORTA, 0xFF); // activate all of the PORTA pin pull-ups io.setInputPolarity(MCP23017_PORTA, 0xFF); // invert all of the PORTA pins input polarity while(true){ // write PORTA to PORTB io.write(1,io.read(0)); } return 0; }
Definition at line 54 of file MCP23017.h.
Constructor & Destructor Documentation
MCP23017 | ( | I2C & | _i2c, |
char | _addr | ||
) |
Constructor.
- Parameters:
-
_i2c pointer to I2C class _addr i2c device address
Definition at line 12 of file MCP23017.cpp.
Member Function Documentation
void init | ( | void | ) |
Software Reset.
Definition at line 19 of file MCP23017.cpp.
char read | ( | char | _port ) |
Read GPIO.
- Parameters:
-
_port port(MCP23017_PORTA or MCP23017_PORTB)
- Returns:
- byte
Definition at line 64 of file MCP23017.cpp.
void setConfig | ( | char | _value ) |
Configure MCP23017 Write IOCON register See MCP23017 datasheet p18 http://ww1.microchip.com/downloads/jp/DeviceDoc/21952b.pdf.
- Attention:
- BANK bit must set 0
- Parameters:
-
_value write byte
Definition at line 38 of file MCP23017.cpp.
void setDirrection | ( | char | _port, |
char | _value | ||
) |
Set I/O dirrection.
- Parameters:
-
_port port(MCP23017_PORTA or MCP23017_PORTB) _value write byte(0=OUTPUT, 1=INPUT)
Definition at line 43 of file MCP23017.cpp.
void setInputPolarity | ( | char | _port, |
char | _value | ||
) |
Set Input Polarity.
- Parameters:
-
_port port(MCP23017_PORTA or MCP23017_PORTB) _value write byte (0=normal, 1=inverted)
Definition at line 53 of file MCP23017.cpp.
void setPullUp | ( | char | _port, |
char | _value | ||
) |
Set pullup.
- Parameters:
-
_port port (MCP23017_PORTA or MCP23017_PORTB) _value write byte (0=Disable, 1=Enable)
Definition at line 48 of file MCP23017.cpp.
void write | ( | char | _port, |
char | _value | ||
) |
Write GPIO.
- Parameters:
-
_port port(MCP23017_PORTA or MCP23017_PORTB) _value write byte
Definition at line 59 of file MCP23017.cpp.
Generated on Wed Jul 13 2022 12:03:45 by 1.7.2