c420mat2  2.1.0.0
Main Page

4-20mA T 2 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Nenad Filipovic
  • Date : Jan 2023.
  • Type : SPI type

Software Support

We provide a library for the 4-20mA T 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 4-20mA T 2 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of 4-20mA T 2 Click boardâ„¢. This driver provides functions to configure analog output current transfer over an industry standard 4-20mA current loop.

The demo application is composed of two sections :

Application Init

Initialization of SPI module and log UART. After driver initialization, default settings turn on the device.

void application_init ( void )
{
log_cfg_t log_cfg;
c420mat2_cfg_t c420mat2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
c420mat2_cfg_setup( &c420mat2_cfg );
C420MAT2_MAP_MIKROBUS( c420mat2_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == c420mat2_init( &c420mat2, &c420mat2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( C420MAT2_ERROR == c420mat2_default_cfg ( &c420mat2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
log_printf( &logger, " -----------------------------\r\n" );
Delay_ms( 100 );
}

Application Task

This example demonstrates the use of the 4-20mA T 2 Click boardâ„¢. This example periodically changes the analog output current transfer from 4mA to 20mA and display status every 5 seconds. Results are being sent to the UART Terminal, where you can track their changes.

void application_task ( void )
{
if ( C420MAT2_OK == c420mat2_set_output_current( &c420mat2, 4.0 ) )
{
log_printf( &logger, " Loop Current: 4.0 mA \r\n" );
log_printf( &logger, " - - - - - - - - - - - - - - -\r\n" );
if ( C420MAT2_OK == c420mat2_get_status ( &c420mat2, &status ) )
{
}
Delay_ms( 5000 );
}
if ( C420MAT2_OK == c420mat2_set_output_current( &c420mat2, 10.0 ) )
{
log_printf( &logger, " Loop Current: 10.0 mA \r\n" );
log_printf( &logger, " - - - - - - - - - - - - - - -\r\n" );
if ( C420MAT2_OK == c420mat2_get_status ( &c420mat2, &status ) )
{
}
Delay_ms( 5000 );
}
if ( C420MAT2_OK == c420mat2_set_output_current( &c420mat2, 15.0 ) )
{
log_printf( &logger, " Loop Current: 15.0 mA \r\n" );
log_printf( &logger, " - - - - - - - - - - - - - - -\r\n" );
if ( C420MAT2_OK == c420mat2_get_status ( &c420mat2, &status ) )
{
}
Delay_ms( 5000 );
}
if ( C420MAT2_OK == c420mat2_set_output_current( &c420mat2, 20.0 ) )
{
log_printf( &logger, " Loop Current: 20.0 mA \r\n" );
log_printf( &logger, " - - - - - - - - - - - - - - -\r\n" );
if ( C420MAT2_OK == c420mat2_get_status ( &c420mat2, &status ) )
{
}
Delay_ms( 5000 );
}
}

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

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.


C420MAT2_ERROR
@ C420MAT2_ERROR
Definition: c420mat2.h:217
c420mat2_get_status
err_t c420mat2_get_status(c420mat2_t *ctx, c420mat2_status_t *status)
4-20mA T 2 set status function.
display_status
void display_status(void)
Definition: main.c:34
C420MAT2_OK
@ C420MAT2_OK
Definition: c420mat2.h:216
c420mat2_default_cfg
err_t c420mat2_default_cfg(c420mat2_t *ctx)
4-20mA T 2 default configuration function.
application_task
void application_task(void)
Definition: main.c:113
c420mat2_status_t
4-20mA T 2 Click status object.
Definition: c420mat2.h:226
c420mat2_init
err_t c420mat2_init(c420mat2_t *ctx, c420mat2_cfg_t *cfg)
4-20mA T 2 initialization function.
C420MAT2_MAP_MIKROBUS
#define C420MAT2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: c420mat2.h:157
c420mat2_set_output_current
err_t c420mat2_set_output_current(c420mat2_t *ctx, float current_ma)
4-20mA T 2 set output current function.
application_init
void application_init(void)
Definition: main.c:75
c420mat2_cfg_setup
void c420mat2_cfg_setup(c420mat2_cfg_t *cfg)
4-20mA T 2 configuration object setup function.
c420mat2_set_lower_limit
err_t c420mat2_set_lower_limit(c420mat2_t *ctx, float lower_limit_ma)
4-20mA T 2 set lower limit function.
c420mat2_t
4-20mA T 2 Click context object.
Definition: c420mat2.h:173
c420mat2_cfg_t
4-20mA T 2 Click configuration object.
Definition: c420mat2.h:192