ldc2  2.0.0.0
Main Page

LDC 2 click

<PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU>

[click Product page](<CLICK_PRODUCT_PAGE_LINK>)


Click library

  • Author : Stefan Filipovic
  • Date : Jul 2021.
  • Type : SPI type

Software Support

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

Standard key functions :

Example key functions :

  • ldc2_measure_resonance_impedance This function measures the resonance impedance and proximity data.
    err_t ldc2_measure_resonance_impedance ( ldc2_t *ctx, uint8_t *prox_data, float *rp_data );
  • ldc2_measure_inductance This function measures the inductance and sensor frequency.
    err_t ldc2_measure_inductance ( ldc2_t *ctx, float *freq, float *inductance );
  • ldc2_get_sensor_frequency This function reads and calculates the sensor frequency.
    err_t ldc2_get_sensor_frequency ( ldc2_t *ctx, float *freq );

Example Description

This example demonstrates the use of LDC 2 click board.

The demo application is composed of two sections :

Application Init

Initializes the driver and configures the click board.

void application_init ( void )
{
log_cfg_t log_cfg;
ldc2_cfg_t ldc2_cfg;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
Delay_ms( 100 );
log_info( &logger, " Application Init " );
// Click initialization.
ldc2_cfg_setup( &ldc2_cfg );
LDC2_MAP_MIKROBUS( ldc2_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == ldc2_init( &ldc2, &ldc2_cfg ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
if ( LDC2_ERROR == ldc2_default_cfg ( &ldc2 ) )
{
log_error( &logger, " Default Config Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Measures the resonance impedance and proximity as well as the inductance and sensor frequency approximately every 200ms and displays all values on the USB UART.

void application_task ( void )
{
uint8_t prox_data = 0;
float rp_data = 0;
float freq = 0;
float inductance = 0;
if ( LDC2_OK == ldc2_measure_resonance_impedance( &ldc2, &prox_data, &rp_data ) )
{
log_printf( &logger, " Proximity: %u\r\n Resonance Impedance: %.3f kOhm\r\n\n", ( uint16_t ) prox_data, rp_data );
}
if ( LDC2_OK == ldc2_measure_inductance( &ldc2, &freq, &inductance ) )
{
log_printf( &logger, " Sensor Frequency: %.3f MHz\r\n Inductance: %.6f uH\r\n\n", freq, inductance );
}
Delay_ms( 200 );
}

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

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. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.


LDC2_ERROR
@ LDC2_ERROR
Definition: ldc2.h:208
LDC2_OK
@ LDC2_OK
Definition: ldc2.h:207
ldc2_cfg_setup
void ldc2_cfg_setup(ldc2_cfg_t *cfg)
LDC 2 configuration object setup function.
application_task
void application_task(void)
Definition: main.c:63
ldc2_default_cfg
err_t ldc2_default_cfg(ldc2_t *ctx)
LDC 2 default configuration function.
ldc2_cfg_t
LDC 2 Click configuration object.
Definition: ldc2.h:184
LDC2_MAP_MIKROBUS
#define LDC2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: ldc2.h:154
ldc2_get_sensor_frequency
err_t ldc2_get_sensor_frequency(ldc2_t *ctx, float *freq)
LDC 2 get sensor frequency function.
ldc2_t
LDC 2 Click context object.
Definition: ldc2.h:169
application_init
void application_init(void)
Definition: main.c:28
ldc2_measure_inductance
err_t ldc2_measure_inductance(ldc2_t *ctx, float *freq, float *inductance)
LDC 2 measure inductance function.
ldc2_measure_resonance_impedance
err_t ldc2_measure_resonance_impedance(ldc2_t *ctx, uint8_t *prox_data, float *rp_data)
LDC 2 measure resonance impedance function.
ldc2_init
err_t ldc2_init(ldc2_t *ctx, ldc2_cfg_t *cfg)
LDC 2 initialization function.