DIGI IN 2 click
PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU
[click Product page](CLICK_PRODUCT_PAGE_LINK)
Click library
- Author : Stefan Ilic
- Date : Dec 2023.
- Type : SPI type
Software Support
We provide a library for the DIGI IN 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 DIGI IN 2 Click driver.
Standard key functions :
digiin2_cfg_setup
Config Object Initialization function.
void digiin2_cfg_setup(digiin2_cfg_t *cfg)
DIGI IN 2 configuration object setup function.
DIGI IN 2 Click configuration object.
Definition: digiin2.h:329
digiin2_init
Initialization function.
err_t digiin2_init(digiin2_t *ctx, digiin2_cfg_t *cfg)
DIGI IN 2 initialization function.
DIGI IN 2 Click context object.
Definition: digiin2.h:306
digiin2_default_cfg
Click Default Configuration function.
err_t digiin2_default_cfg(digiin2_t *ctx)
DIGI IN 2 default configuration function.
Example key functions :
digiin2_get_flt_pin
This function is used to get state of the FLT pin.
uint8_t digiin2_get_flt_pin(digiin2_t *ctx)
DIGI IN 2 get FLT pin state function.
digiin2_write_reg
This function is used to write data into the selected register by using SPI serial interface.
err_t digiin2_write_reg(digiin2_t *ctx, uint8_t reg, uint8_t data_in)
DIGI IN 2 register write function.
digiin2_read_reg
This function reads a data byte from the selected register by using SPI serial interface.
err_t digiin2_read_reg(digiin2_t *ctx, uint8_t reg, uint8_t *data_out)
DIGI IN 2 register reading function.
Example Description
This example demonstrates the use of DIGI IN 2 Click board by reading and displaying the state of the channels.
The demo application is composed of two sections :
Application Init
Initializes the driver, performs the click default configuration.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( SPI_MASTER_ERROR ==
digiin2_init( &digiin2, &digiin2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ DIGIIN2_ERROR
Definition: digiin2.h:355
#define DIGIIN2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: digiin2.h:289
void application_init(void)
Definition: main.c:28
Application Task
Reads and displays on the USB UART the channel state every second.
{
uint8_t channel_data = 0;
{
{
log_printf( &logger, "Channel 1 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 1 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 2 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 2 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 3 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 3 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 4 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 4 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 5 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 5 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 6 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 6 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 7 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 7 counter: LOW \r\n" );
}
{
log_printf( &logger, "Channel 8 counter: HIGH \r\n" );
}
else
{
log_printf( &logger, "Channel 8 counter: LOW \r\n" );
}
log_printf( &logger, "- - - - - - - - - - - - - -\r\n" );
}
else
{
log_error( &logger, " Read error." );
}
{
uint8_t flt_data = 0;
log_printf( &logger, "Fault1 data: 0x%.2X \r\n", ( uint16_t ) flt_data );
log_printf( &logger, "Fault2 data: 0x%.2X \r\n", ( uint16_t ) flt_data );
log_printf( &logger, "- - - - - - - - - - - - - -\r\n" );
}
Delay_ms( 1000 );
}
@ DIGIIN2_OK
Definition: digiin2.h:354
#define DIGIIN2_REG_DISTATE
DIGI IN 2 description register.
Definition: digiin2.h:70
#define DIGIIN2_REG_FAULT
Definition: digiin2.h:71
#define DIGIIN2_REG_FAULT2
Definition: digiin2.h:83
#define DIGIIN2_CHANNEL_3_MASK
Definition: digiin2.h:121
#define DIGIIN2_CHANNEL_8_MASK
Definition: digiin2.h:126
#define DIGIIN2_CHANNEL_5_MASK
Definition: digiin2.h:123
#define DIGIIN2_CHANNEL_4_MASK
Definition: digiin2.h:122
#define DIGIIN2_CHANNEL_1_MASK
DIGI IN 2 DISTATE register setting.
Definition: digiin2.h:119
#define DIGIIN2_PIN_STATE_HIGH
DIGI IN 2 pin state setting.
Definition: digiin2.h:241
#define DIGIIN2_CHANNEL_2_MASK
Definition: digiin2.h:120
#define DIGIIN2_CHANNEL_7_MASK
Definition: digiin2.h:125
#define DIGIIN2_CHANNEL_6_MASK
Definition: digiin2.h:124
void digiin2_pulse_latch(digiin2_t *ctx)
DIGI IN 2 send latch pulse function.
void application_task(void)
Definition: main.c:64
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.DIGIIN2
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.