How does it work?
Expand 2 Click is based on the MCP23017, a 16-bit general purpose parallel I/O expansion for I2C bus from Microchip. The MCP23017 consists of multiple 8-bit configuration registers for input, output, and polarity selection. The host MCU can enable the I/Os as either inputs or outputs by writing the I/O configuration bits with data for each input or output kept in the corresponding input or output register. This port expander represents a simple solution when additional I/Os are needed while keeping interconnections to a minimum.
This Click board™ communicates with MCU using the standard I2C 2-Wire interface with a maximum clock frequency of 1.7MHz. The MCP23017 has a 7-bit slave address with the first four MSBs fixed to 0100. The address pins A0, A1, and A2, are programmed by the user and determine the value of the last three LSBs of the slave address, which can be selected by positioning onboard SMD jumpers labeled as ADDR SEL to an appropriate position marked as 1 or 0. This way, the MCP23017 provides the opportunity of the 64 possible different I2C addresses by positioning the SMD jumper to an appropriate position.
Besides, it also features an interrupt feature, routed to the INT pin of the mikroBUS™ socket, indicating to the host controller that an input state has been changed. Two interrupt pins on the MCP23017 can be associated with their respective ports or logically OR’ed together so that both pins will activate if either port causes an interrupt. The desired interrupt can be selected by positioning an onboard SMD jumper labeled INT SEL to an appropriate position.
This Click board™ can operate with both 3.3V and 5V logic voltage levels selected via the PWR SEL jumper. This way, it is allowed for both 3.3V and 5V capable MCUs to use the communication lines properly. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.
Specifications
Type
Port expander
Applications
Can be used to control a wide range of peripheral signals in portable equipment, industrial controllers, and more
On-board modules
MCP23017 – general purpose parallel I/O expansion from Microchip
Key Features
16-bit remote bidirectional I/O port, high-speed I2C interface, configurable interrupt, polarity inversion, reset feature, low power consumption, and more
Interface
I2C
Feature
No ClickID
Compatibility
mikroBUS™
Click board size
L (57.15 x 25.4 mm)
Input Voltage
3.3V or 5V
Pinout diagram
This table shows how the pinout on Expand 2 Click corresponds to the pinout on the mikroBUS™ socket (the latter shown in the two middle columns).
Onboard settings and indicators
Label | Name | Default | Description |
---|---|---|---|
LD1 | PWR | – | Power LED Indicator |
JP1 | PWR SEL | Left | Logic Level Voltage Selection 3V3/5V: Left position 3V3, Right position 5V |
JP2 | INT SEL | Upper | Interrupt Selection INTA/INTB: Upper position INTA, Lower position INTB |
JP3-JP5 | ADDR SEL | Right | I2C Address Selection 1/0: Left position 1, Right position 0 |
J1-J2 | PA-PB | Unpopulated | I/O Expander Ports |
Expand 2 Click electrical specifications
Description | Min | Typ | Max | Unit |
---|---|---|---|---|
Supply Voltage | 3.3 | – | 5 | V |
Output Current Source/Sink | – | – | 25 | mA |
Clock Frequency | – | – | 1.7 | MHz |
Software Support
We provide a library for the Expand 2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.
Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Library Description
This library contains API for Expand 2 Click driver.
Key functions
-
Function set bit to 8-bit register address from PORTA of MCP23017 chip.
-
Function toggle bit from 8-bit register address from PORTA of MCP23017 chip.
-
Function clear bit from 8-bit register address from PORTA of MCP23017 chip.
Example Description
This application demonstrates the use of the Expand 2 Click board™.
void application_task ( void )
{
// Task implementation.
uint8_t port_status;
uint8_t pin_position;
for ( pin_position = 0; pin_position < 8; pin_position++ )
{
expand2_set_port_a( &expand2, EXPAND2_I2C_MODULE_ADDRESS_0, pin_position );
port_status = expand2_read_port_a( &expand2, EXPAND2_I2C_MODULE_ADDRESS_0 );
log_printf( &logger, " Status PA (output): %drn", (uint16_t) port_status );
port_status = expand2_read_port_b( &expand2, EXPAND2_I2C_MODULE_ADDRESS_0 );
log_printf( &logger, " Status PB (input) : %d rn", (uint16_t) port_status );
log_printf( &logger, "----------------rn" );
Delay_ms( 3000 );
}
}
The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Other Mikroe Libraries used in the example:
- MikroSDK.Board
- MikroSDK.Log
- Click.Expand2
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.
mikroSDK
This Click board™ is supported with mikroSDK – MikroElektronika Software Development Kit. To ensure proper operation of mikroSDK compliant Click board™ demo applications, mikroSDK should be downloaded from the LibStock and installed for the compiler you are using.
For more information about mikroSDK, visit the official page.