Difference between revisions of "Unit MCP230XX"
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
---- | ---- | ||
− | '''Microchip MCP230XX I/O | + | '''Microchip MCP230XX I/O Expander Driver unit''' |
The Microchip MCP23008 and MCP23017 are 8 or 16 bit I/O expanders that provide GPIO pin control functions over an I2C connection. | The Microchip MCP23008 and MCP23017 are 8 or 16 bit I/O expanders that provide GPIO pin control functions over an I2C connection. | ||
Line 74: | Line 74: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''MCP230XX chip | + | <div style="font-size: 14px; padding-left: 12px;">'''MCP230XX chip''' <code> MCP230XX_CHIP_* </code></div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 88: | Line 88: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''MCP230XX I2C | + | <div style="font-size: 14px; padding-left: 12px;">'''MCP230XX I2C''' <code> MCP230XX_I2C_* </code></div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 123: | Line 123: | ||
---- | ---- | ||
− | '' | + | |
+ | '''MCP230XX GPIO types''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PMCP230XXGPIO = ^TMCP230XXGPIO;</code> | ||
+ | |||
+ | <code>TMCP230XXGPIO = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''GPIO Properties'' | ||
+ | |- | ||
+ | | <code>GPIO:TGPIODevice;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''MCP230XX Properties'' | ||
+ | |- | ||
+ | | <code>I2C:PI2CDevice;</code> | ||
+ | | The I2C device this GPIO is connected to | ||
+ | |- | ||
+ | | <code>Address:Word;</code> | ||
+ | | The I2C address of the device | ||
+ | |- | ||
+ | | <code>Chip:LongWord;</code> | ||
+ | | The chip type (eg MCP230XX_CHIP_MCP23008) | ||
+ | |- | ||
+ | | <code>Size:LongWord;</code> | ||
+ | | Size of an I2C read/write for the device | ||
+ | |- | ||
+ | | <code>GPIOReg:Byte;</code> | ||
+ | | GPIO port register for the device | ||
+ | |- | ||
+ | | <code>GPPUReg:Byte;</code> | ||
+ | | GPPU pull up resistor register for the device | ||
+ | |- | ||
+ | | <code>IODIRReg:Byte;</code> | ||
+ | | IODIR I/O direction register for the device | ||
+ | |- | ||
+ | | <code>GPIOValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for GPIO port values (Output only) | ||
+ | |- | ||
+ | | <code>GPPUValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for GPPU pull up values | ||
+ | |- | ||
+ | | <code>IODIRValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for IODIR I/O direction values | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === | ||
Line 142: | Line 191: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2C |
| The I2C device this MCP23008 is connected to | | The I2C device this MCP23008 is connected to | ||
|- | |- | ||
− | ! | + | ! Address |
| The I2C address for this MCP23008 | | The I2C address for this MCP23008 | ||
|- | |- | ||
− | ! | + | ! Return |
| Pointer to the new GPIO device or nil on failure | | Pointer to the new GPIO device or nil on failure | ||
|- | |- | ||
Line 160: | Line 209: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2C |
| The I2C device this MCP23017 is connected to | | The I2C device this MCP23017 is connected to | ||
|- | |- | ||
− | ! | + | ! Address |
| The I2C address for this MCP23017 | | The I2C address for this MCP23017 | ||
|- | |- | ||
− | ! | + | ! Return |
| Pointer to the new GPIO device or nil on failure | | Pointer to the new GPIO device or nil on failure | ||
|- | |- | ||
Line 178: | Line 227: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! GPIO |
| The GPIO device to destroy | | The GPIO device to destroy | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 196: | Line 245: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceStart instead | + | | Not intended to be called directly by applications, use GPIODeviceStart instead. |
|- | |- | ||
|} | |} | ||
Line 208: | Line 257: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceStop instead | + | | Not intended to be called directly by applications, use GPIODeviceStop instead. |
|- | |- | ||
|} | |} | ||
Line 220: | Line 269: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceRead instead | + | | Not intended to be called directly by applications, use GPIODeviceRead instead. |
Will read only a single register byte | Will read only a single register byte | ||
|- | |- | ||
Line 233: | Line 282: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceWrite instead | + | | Not intended to be called directly by applications, use GPIODeviceWrite instead. |
Will write only a single register byte | Will write only a single register byte | ||
|- | |- | ||
Line 246: | Line 295: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceInputGet instead | + | | Not intended to be called directly by applications, use GPIODeviceInputGet instead. |
|- | |- | ||
|} | |} | ||
Line 258: | Line 307: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceOutputSet instead | + | | Not intended to be called directly by applications, use GPIODeviceOutputSet instead. |
|- | |- | ||
|} | |} | ||
Line 270: | Line 319: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODevicePullGet instead | + | | Not intended to be called directly by applications, use GPIODevicePullGet instead. |
|- | |- | ||
|} | |} | ||
Line 282: | Line 331: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODevicePullSelect instead | + | | Not intended to be called directly by applications, use GPIODevicePullSelect instead. |
|- | |- | ||
|} | |} | ||
Line 294: | Line 343: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceFunctionGet instead | + | | Not intended to be called directly by applications, use GPIODeviceFunctionGet instead. |
|- | |- | ||
|} | |} | ||
Line 306: | Line 355: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead | + | | Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead. |
|- | |- | ||
|} | |} |
Latest revision as of 05:44, 31 August 2021
Return to Unit Reference
Description
Microchip MCP230XX I/O Expander Driver unit
The Microchip MCP23008 and MCP23017 are 8 or 16 bit I/O expanders that provide GPIO pin control functions over an I2C connection.
The device can be represented in Ultibo as a standard GPIO device which is accessible via the GPIO unit functions. Because the MCP230XX is a chip that can be used and configured in multiple different scenarios this unit does not autocreate a GPIO device, instead you need to call the function MCP23008GPIOCreate or MCP23017GPIOCreate and pass an I2C device and address. The functions will create and return a GPIO device with the appropriate number of pins and other information for the specified chip, the returned devices will have been registered with the GPIO device unit and started ready for use.
Both devices also come in an SPI interface version, these are not currently supported by this unit.
Note: This unit does not currently implement the interrupt capabilities of the MCP230XX chips however it could be expanded to allow the interrupt pin to be connected to a GPIO pin on the SoC and use a trigger event from that to enable GPIOInputWait/GPIOInputEvent functions for the MCP230XX chips.
Constants
MCP23008_*
MCP23008_GPIO_DESCRIPTION = 'Microchip MCP23008 8-bit I/O Expander';
|
Description of MCP23008 device |
MCP23017_GPIO_DESCRIPTION = 'Microchip MCP23016 16-bit I/O Expander';
|
Description of MCP23017 device |
MCP23008_GPIO_MIN_PIN = GPIO_PIN_0;
|
|
MCP23008_GPIO_MAX_PIN = GPIO_PIN_7;
|
|
MCP23008_GPIO_PIN_COUNT = 8;
|
|
MCP23017_GPIO_MIN_PIN = GPIO_PIN_0;
|
|
MCP23017_GPIO_MAX_PIN = GPIO_PIN_15;
|
|
MCP23017_GPIO_PIN_COUNT = 16;
|
|
MCP230XX_GPIO_MAX_LEVEL = GPIO_LEVEL_HIGH;
|
|
MCP230XX_GPIO_MAX_PULL = GPIO_PULL_UP;
|
|
MCP230XX_GPIO_MIN_FUNCTION = GPIO_FUNCTION_IN;
|
|
MCP230XX_GPIO_MAX_FUNCTION = GPIO_FUNCTION_OUT;
|
MCP230XX_CHIP_*
MCP230XX_CHIP_MCP23008 = 0;
|
|
MCP230XX_CHIP_MCP23017 = 1;
|
MCP230XX_I2C_*
MCP230XX_I2C_RATE = 400000;
|
Default I2C clock rate (Device supports 100KHz, 400KHz and 1.7MHz) |
MCP23008_I2C_SIZE = 1;
|
Number of bytes to read/write all pin values for any register |
MCP23017_I2C_SIZE = 2;
|
Number of bytes to read/write all pin values for any register |
MCP230XX_I2C_MAX_SIZE = 2;
|
Maximum number of bytes to read/write all pin values for any register |
MCP23008_I2C_MAX_REG = $0A;
|
Maximum register address for the I2C interface |
MCP23017_I2C_MAX_REG = $1A;
|
Maximum register address for the I2C interface (Only 21 (0x15) registers exists, mappings differ between modes) |
Type definitions
MCP230XX GPIO types
PMCP230XXGPIO = ^TMCP230XXGPIO;
TMCP230XXGPIO = record
GPIO Properties | |
GPIO:TGPIODevice;
|
|
MCP230XX Properties | |
I2C:PI2CDevice;
|
The I2C device this GPIO is connected to |
Address:Word;
|
The I2C address of the device |
Chip:LongWord;
|
The chip type (eg MCP230XX_CHIP_MCP23008) |
Size:LongWord;
|
Size of an I2C read/write for the device |
GPIOReg:Byte;
|
GPIO port register for the device |
GPPUReg:Byte;
|
GPPU pull up resistor register for the device |
IODIRReg:Byte;
|
IODIR I/O direction register for the device |
GPIOValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for GPIO port values (Output only) |
GPPUValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for GPPU pull up values |
IODIRValues:array[0..MCP230XX_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for IODIR I/O direction values |
Public variables
None defined
Function declarations
MCP230XX functions
function MCP23008GPIOCreate(I2C:PI2CDevice; Address:Word):PGPIODevice;
I2C | The I2C device this MCP23008 is connected to |
---|---|
Address | The I2C address for this MCP23008 |
Return | Pointer to the new GPIO device or nil on failure |
function MCP23017GPIOCreate(I2C:PI2CDevice; Address:Word):PGPIODevice;
I2C | The I2C device this MCP23017 is connected to |
---|---|
Address | The I2C address for this MCP23017 |
Return | Pointer to the new GPIO device or nil on failure |
function MCP230XXGPIODestroy(GPIO:PGPIODevice):LongWord;
GPIO | The GPIO device to destroy |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
MCP230XX GPIO functions
function MCP230XXGPIOStart(GPIO:PGPIODevice):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceStart instead. |
---|
function MCP230XXGPIOStop(GPIO:PGPIODevice):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceStop instead. |
---|
function MCP230XXGPIORead(GPIO:PGPIODevice; Reg:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceRead instead.
Will read only a single register byte |
---|
procedure MCP230XXGPIOWrite(GPIO:PGPIODevice; Reg,Value:LongWord);
Note | Not intended to be called directly by applications, use GPIODeviceWrite instead.
Will write only a single register byte |
---|
function MCP230XXGPIOInputGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceInputGet instead. |
---|
function MCP230XXGPIOOutputSet(GPIO:PGPIODevice; Pin,Level:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceOutputSet instead. |
---|
function MCP230XXGPIOPullGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODevicePullGet instead. |
---|
function MCP230XXGPIOPullSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODevicePullSelect instead. |
---|
function MCP230XXGPIOFunctionGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceFunctionGet instead. |
---|
function MCP230XXGPIOFunctionSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead. |
---|
Return to Unit Reference