expand18  2.1.0.0
Main Page

Expand 18 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Apr 2024.
  • Type : SPI type

Software Support

We provide a library for the Expand 18 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 18 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of Expand 18 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 the port 0 as output and the port 1 as input with pull-down enabled.

void application_init ( void )
{
log_cfg_t log_cfg;
expand18_cfg_t expand18_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
expand18_cfg_setup( &expand18_cfg );
EXPAND18_MAP_MIKROBUS( expand18_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == expand18_init( &expand18, &expand18_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( EXPAND18_ERROR == expand18_default_cfg ( &expand18 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Sets the pins of the port 0 and then reads the status of both ports and displays the results on the USB UART approximately once per second.

void application_task ( void )
{
uint8_t port_value = 0;
for ( uint16_t pin_num = EXPAND18_PIN_0_MASK; pin_num <= EXPAND18_PIN_7_MASK; pin_num <<= 1 )
{
expand18_set_all_pins_value( &expand18, pin_num );
expand18_read_port_value( &expand18, EXPAND18_PORT_0, &port_value );
log_printf( &logger, " Status port 0 (output): 0x%.2X\r\n", ( uint16_t ) port_value );
expand18_read_port_value( &expand18, EXPAND18_PORT_1, &port_value );
log_printf( &logger, " Status port 1 (input) : 0x%.2X\r\n\n", ( uint16_t ) port_value );
Delay_ms( 1000 );
}
}

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.Expand18

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.


expand18_set_all_pins_value
err_t expand18_set_all_pins_value(expand18_t *ctx, uint8_t set_mask)
Expand 18 set all pins value function.
EXPAND18_PORT_0
#define EXPAND18_PORT_0
Expand 18 port values.
Definition: expand18.h:142
application_task
void application_task(void)
Definition: main.c:66
expand18_set_pin_direction
err_t expand18_set_pin_direction(expand18_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask)
Expand 18 set pin direction function.
expand18_cfg_setup
void expand18_cfg_setup(expand18_cfg_t *cfg)
Expand 18 configuration object setup function.
expand18_default_cfg
err_t expand18_default_cfg(expand18_t *ctx)
Expand 18 default configuration function.
application_init
void application_init(void)
Definition: main.c:30
EXPAND18_PIN_0_MASK
#define EXPAND18_PIN_0_MASK
Definition: expand18.h:128
expand18_cfg_t
Expand 18 Click configuration object.
Definition: expand18.h:244
EXPAND18_PIN_7_MASK
#define EXPAND18_PIN_7_MASK
Definition: expand18.h:135
EXPAND18_MAP_MIKROBUS
#define EXPAND18_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: expand18.h:207
expand18_read_port_value
err_t expand18_read_port_value(expand18_t *ctx, uint8_t port, uint8_t *data_out)
Expand 18 read port value function.
expand18_init
err_t expand18_init(expand18_t *ctx, expand18_cfg_t *cfg)
Expand 18 initialization function.
EXPAND18_PORT_1
#define EXPAND18_PORT_1
Definition: expand18.h:143
expand18_t
Expand 18 Click context object.
Definition: expand18.h:223
EXPAND18_ERROR
@ EXPAND18_ERROR
Definition: expand18.h:271