MCP23017 Input/Output functions. More...
Go to the source code of this file.
Data Structures | |
struct | _MCP23017 |
Macros | |
#define | MCP23017_REG_IODIRA 0x00 |
#define | MCP23017_REG_IODIRB 0x01 |
#define | MCP23017_REG_IPOLA 0x02 |
#define | MCP23017_REG_IPOLB 0x03 |
#define | MCP23017_REG_GPINTENA 0x04 |
#define | MCP23017_REG_GPINTENB 0x05 |
#define | MCP23017_REG_DEFVALA 0x06 |
#define | MCP23017_REG_DEFVALB 0x07 |
#define | MCP23017_REG_INTCONA 0x08 |
#define | MCP23017_REG_INTCONB 0x09 |
#define | MCP23017_REG_IOCON 0x0A |
#define | MCP23017_REG_GPPUA 0x0C |
#define | MCP23017_REG_GPPUB 0x0D |
#define | MCP23017_REG_INTFA 0x0E |
#define | MCP23017_REG_INTFB 0x0F |
#define | MCP23017_REG_INTCAPA 0x10 |
#define | MCP23017_REG_INTCAPB 0x11 |
#define | MCP23017_REG_GPIOA 0x12 |
#define | MCP23017_REG_GPIOB 0x13 |
#define | MCP23017_REG_OLATA 0x14 |
#define | MCP23017_REG_OLATB 0x15 |
#define | MCP23017_ADDRESS 0x40 /*Base address if A0 to A3 are all 0 */ |
#define | MCP23017_GPA0 0 |
#define | MCP23017_GPA1 1 |
#define | MCP23017_GPA2 2 |
#define | MCP23017_GPA3 3 |
#define | MCP23017_GPA4 4 |
#define | MCP23017_GPA5 5 |
#define | MCP23017_GPA6 6 |
#define | MCP23017_GPA7 7 |
#define | MCP23017_GPB0 8 |
#define | MCP23017_GPB1 9 |
#define | MCP23017_GPB2 10 |
#define | MCP23017_GPB3 11 |
#define | MCP23017_GPB4 12 |
#define | MCP23017_GPB5 13 |
#define | MCP23017_GPB6 14 |
#define | MCP23017_GPB7 15 |
#define | MCP23017_SETPIN 0x80 |
#define | MCP23017_CLEARPIN 0 |
#define | mcp23017_WritePin(obj, pin) mcp23017_WritePin(obj, pin | 0x80) |
#define | mcp23017_ClearPin(obj, pin) mcp23017_WritePin(obj, pin & 0x7f) |
#define | mcp23017_ReadPins(obj) ((obj)->pin.Val) |
Typedefs | |
typedef struct _MCP23017 | MCP23017 |
Functions | |
INT8 | mcp23017_Init (MCP23017 *obj) |
INT8 | mcp23017_ConfigDir (MCP23017 *obj, UINT16 dir) |
INT8 | mcp23017_ConfigDirMask (MCP23017 *obj, UINT16 dir, UINT16 mask) |
INT8 | mcp23017_ConfigPullups (MCP23017 *obj, UINT16 pullUps) |
INT8 | mcp23017_ConfigIntPins (MCP23017 *obj, UINT16 intPins) |
INT8 | mcp23017_WritePin (MCP23017 *obj, UINT8 pinVal) |
INT8 | mcp23017_WriteMask (MCP23017 *obj, UINT16 val, UINT16 mask) |
INT8 | mcp23017_ReadPins (MCP23017 *obj) |
MCP23017 Input/Output functions.
MCP23017 I/O Expander functions.
Software License Agreement
The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.
THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
File History
2011-06-03, David Hosken (DH):
Functions for using the MCP23017 I/O Expander
The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.
#define mcp23017_ClearPin | ( | obj, | |
pin | |||
) | mcp23017_WritePin(obj, pin & 0x7f) |
Clear a single pin. For example, to set pin GPA5, use command: mcp23017_ClearPin(0x40, MCP23017_GPA5)
obj | Structure with data for MCP23017 chip |
pin | Address of pin to clear. Is a value from 0 to 15. 0=GPA0, 7=GPA7 8=GPB0 and 15=GPB7 |
#define mcp23017_ReadPins | ( | obj) | ((obj)->pin.Val) |
Returns the current pin values saved in the MCP23017 object. The current pin values are NOT read from the MCP23017 chip. The mcp23017_ReadPins() will cause MCP23017 chip to be read. Use DINPTST1_IOX_MASK_XXX constants to test if pin is 0 or 1.
obj | Pointer to structure with data for MCP23017 chip |
#define mcp23017_WritePin | ( | obj, | |
pin | |||
) | mcp23017_WritePin(obj, pin | 0x80) |
Set a single pin. For example, to set pin GPA5, use command: mcp23017_WritePin(0x40, MCP23017_GPA5)
obj | Structure with data for MCP23017 chip |
pin | Address of pin to set. Is a value from 0 to 15. 0=GPA0, 7=GPA7 8=GPB0 and 15=GPB7 |
Structure containing information for a MCP23017 chip. Can be multiple MCP23017 on a bus.
INT8 mcp23017_ConfigDir | ( | MCP23017 * | obj, |
UINT16 | dir | ||
) |
Configure direction of pins.
obj | Structure with data for MCP23017 chip |
dir | Direction bit for 16 port pins |
Configure direction of pins.
obj | Structure with data for MCP23017 chip |
dir | Bits indicate direction of I/O pins. A 0 sets pin to output, and a 1 sets pin to input. |
INT8 mcp23017_ConfigDirMask | ( | MCP23017 * | obj, |
UINT16 | dir, | ||
UINT16 | mask | ||
) |
Configure direction of pins. A mask and value is supplied.
obj | Structure with data for MCP23017 chip |
dir | Direction bit for 16 port pins |
mask | 16-bit mask |
INT8 mcp23017_ConfigIntPins | ( | MCP23017 * | obj, |
UINT16 | intPins | ||
) |
Configures what pins to use for interrupt-on-change function. If the value of any of these pins change, a interrupt will be generated.
obj | Structure with data for MCP23017 chip |
intPins | Bits indicate what pins to use for interrupt-on-change function |
INT8 mcp23017_ConfigPullups | ( | MCP23017 * | obj, |
UINT16 | pullUps | ||
) |
Configure pull-up resistors.
obj | Structure with data for MCP23017 chip |
pullUps | Bits indicate if pull-up's are active for 16 port pins |
Configure pull-up resistors.
obj | Structure with data for MCP23017 chip |
pullUps | Bits indicate if pull-up is active. |
INT8 mcp23017_Init | ( | MCP23017 * | obj) |
Initializes the MCP23017 I/O Expander
obj | Structure with data for MCP23017 chip |
Initializes the MCP23017 I/O Expander
obj | Structure with data for MCP23017 chip. |
INT8 mcp23017_ReadPins | ( | MCP23017 * | obj) |
Reads value of all pins, and updates obj->pin. This function does a read of the MCP23017 chip, and updates the pin value in the given MCP23017 object.
obj | Pointer to structure with data for MCP23017 chip |
INT8 mcp23017_WriteMask | ( | MCP23017 * | obj, |
UINT16 | val, | ||
UINT16 | mask | ||
) |
Set/clear all pins by providing a 16 bit value and mask. For example, to set pin 0 and 7, and clear pins 4 and 5, use command: mcp23017_WriteMask(0x40, 0b0000000010000001, 0b0000000010110001);
obj | Structure with data for MCP23017 chip |
val | 16-bit pin values |
mask | 16-bit mask |
INT8 mcp23017_WritePin | ( | MCP23017 * | obj, |
UINT8 | pinVal | ||
) |
Write value to pin. For example, to set pin GPA5, use command: mcp23017_WritePin(0x40, MCP23017_GPA5 | MCP23017_SETPIN) Or, to clear pin GPB7, use command: mcp23017_WritePin(0x40, MCP23017_GPB7 | MCP23017_CLEARPIN)
obj | Structure with data for MCP23017 chip |
pinVal | Indicates what pin to set/clear, and value. Bits 0-3 give pin's address, and bit 7 it's value |