Expand 16 click
Expand 16 Click is a compact add-on board with a multi-port I/O expander. This board features the FLX6408, a fully configurable 8-bit GPIO expander from ON Semiconductor. It brings eight independently configurable input/output ports, with a 6mA output drive, when configured in the output mode.
click Product page
Click library
- Author : Stefan Ilic
- Date : Oct 2023.
- Type : I2C type
Software Support
We provide a library for the Expand 16 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 16 Click driver.
Standard key functions :
expand16_cfg_setup
Config Object Initialization function.
void expand16_cfg_setup(expand16_cfg_t *cfg)
Expand 16 configuration object setup function.
Expand 16 Click configuration object.
Definition: expand16.h:185
expand16_init
Initialization function.
err_t expand16_init(expand16_t *ctx, expand16_cfg_t *cfg)
Expand 16 initialization function.
Expand 16 Click context object.
Definition: expand16.h:165
expand16_default_cfg
Click Default Configuration function.
err_t expand16_default_cfg(expand16_t *ctx)
Expand 16 default configuration function.
Example key functions :
expand16_write_reg
Expand 16 register write function.
err_t expand16_write_reg(expand16_t *ctx, uint8_t reg, uint8_t data_in)
Expand 16 register write function.
expand16_set_io_dir
Expand 16 set pin input or output direction function.
err_t expand16_set_io_dir(expand16_t *ctx, uint8_t input_pins, uint8_t output_pins)
Expand 16 set pin input or output direction function.
expand16_set_output_state
Expand 16 set output pins state function.
err_t expand16_set_output_state(expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 16 set output pins state function.
Example Description
This example demonstrates the use of Expand 16 click board by setting and reading
the ports state.
The demo application is composed of two sections :
Application Init
Initializes the driver and performs the click default configuration which sets
half of the pins as output ( GPIO4, GPIO5, GPIO6 and GPIO7 ) and the other half of the pins as inputs ( GPIO0, GPIO1, GPIO2 and GPIO3 ).
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( I2C_MASTER_ERROR ==
expand16_init( &expand16, &expand16_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
uint8_t dev_id = 0;
{
log_error( &logger, " Communication error." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ EXPAND16_ERROR
Definition: expand16.h:204
#define EXPAND16_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: expand16.h:151
#define EXPAND16_REG_DEV_ID_AND_CTRL
Expand 16 description register.
Definition: expand16.h:69
#define EXPAND16_DEVICE_ID
Expand 16 device ID.
Definition: expand16.h:117
#define EXPAND16_DEVICE_ID_MASK
Definition: expand16.h:118
err_t expand16_read_reg(expand16_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 16 register read function.
void application_init(void)
Definition: main.c:47
Application Task
Sets the state of the output pins and then reads the status of input pins
and displays the results on the USB UART approximately 2 seconds.
{
uint8_t tmp_data = 0;
log_printf( &logger, "Output pins state: HIGH \r\n" );
log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
show_input_pin_state( tmp_data );
Delay_ms( 2000 );
log_printf( &logger, "Output pins state: LOW \r\n" );
log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
show_input_pin_state( tmp_data );
Delay_ms( 2000 );
}
#define EXPAND16_REG_INPUT_STATE
Definition: expand16.h:76
#define EXPAND16_PIN_MASK_NONE
Expand 16 description setting.
Definition: expand16.h:96
#define EXPAND16_PIN_MASK_GPIO_5
Definition: expand16.h:102
#define EXPAND16_PIN_MASK_GPIO_4
Definition: expand16.h:101
#define EXPAND16_PIN_MASK_GPIO_6
Definition: expand16.h:103
#define EXPAND16_PIN_MASK_GPIO_7
Definition: expand16.h:104
void application_task(void)
Definition: main.c:91
Note
In order for this example to work as intended it is necessary to connect the input and output pins
eg. GPIO0 and GPIO4, GPIO1 and GPIO5 etc. Floating input pins will be shown as a low state.
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.Expand16
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.