ldc  2.0.0.0
Main Page

LDC click

<PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU>

[click Product page](<CLICK_PRODUCT_PAGE_LINK>)


Click library

  • Author : Luka Filipovic
  • Date : Jul 2021.
  • Type : I2C type

Software Support

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

Standard key functions :

Example key functions :

Example Description

This example showcases abillity of the device to detect

metal objects. It configures device for reading data from channel 0, checks if ID's are OK and reads data when interrupt is asserted and logs result.

The demo application is composed of two sections :

Application Init

Initialization of communication modules (I2C, UART) and

additional pins. Then configures device for reading data from channel 0, and checks if device ID's are correctly read.

void application_init ( void )
{
log_cfg_t log_cfg;
ldc_cfg_t ldc_cfg;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
ldc_cfg_setup( &ldc_cfg );
LDC_MAP_MIKROBUS( ldc_cfg, MIKROBUS_1 );
err_t init_flag = ldc_init( &ldc, &ldc_cfg );
if ( I2C_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
if ( ldc_default_cfg ( &ldc ) < 0 )
{
log_error( &logger, " Default configuration. " );
for ( ; ; );
}
uint16_t temp_data = 0;
log_printf( &logger, "> Manufacturer ID: 0x%.4X\r\n", temp_data );
if ( temp_data != LDC_MANUFACTURER_ID )
{
log_error( &logger, " Manufacturer ID. " );
for ( ; ; );
}
ldc_generic_read( &ldc, LDC_REG_DEVICE_ID, &temp_data );
log_printf( &logger, "> Device ID 0x%.4X\r\n", temp_data );
if ( temp_data != LDC_DEVICE_ID )
{
log_error( &logger, " Device ID. " );
for ( ; ; );
}
Delay_ms( 1000 );
log_info( &logger, " Application Task " );
}

Application Task

Chekcs if interrupt pin is asserted, if so reads data from channel 0.

If no error is detected logs ADC data read from device. It will log error data if some are detected.

void application_task ( void )
{
if ( ldc_get_interrupt( &ldc ) )
{
uint16_t temp_data = 0;
ldc_generic_read( &ldc, LDC_REG_DATA_CH0, &temp_data );
if ( !( temp_data >> 12 ) )
{
log_printf( &logger, "> Data: %u\r\n", temp_data & 0xFFF );
Delay_ms( 500 );
}
else
{
temp_data >>= 12;
if ( temp_data & 0x8 )
{
log_error( &logger, " Under-range" );
}
if ( temp_data & 0x4 )
{
log_error( &logger, " Over-range" );
}
if ( temp_data & 0x3 )
{
log_error( &logger, " Watchdog" );
}
}
}
}

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

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.


ldc_generic_write
err_t ldc_generic_write(ldc_t *ctx, uint8_t reg, uint16_t tx_data)
LDC I2C writing function.
ldc_t
LDC Click context object.
Definition: ldc.h:133
ldc_default_cfg
err_t ldc_default_cfg(ldc_t *ctx)
LDC default configuration function.
ldc_init
err_t ldc_init(ldc_t *ctx, ldc_cfg_t *cfg)
LDC initialization function.
ldc_cfg_setup
void ldc_cfg_setup(ldc_cfg_t *cfg)
LDC configuration object setup function.
LDC_MAP_MIKROBUS
#define LDC_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: ldc.h:120
application_task
void application_task(void)
Definition: main.c:84
LDC_DEVICE_ID
#define LDC_DEVICE_ID
Definition: ldc.h:95
ldc_get_interrupt
uint8_t ldc_get_interrupt(ldc_t *ctx)
Get interrupt pin status.
LDC_REG_MANUFACTURER_ID
#define LDC_REG_MANUFACTURER_ID
Definition: ldc.h:75
ldc_generic_read
err_t ldc_generic_read(ldc_t *ctx, uint8_t reg, uint16_t *rx_data)
LDC I2C reading function.
LDC_REG_DEVICE_ID
#define LDC_REG_DEVICE_ID
Definition: ldc.h:76
application_init
void application_init(void)
Definition: main.c:34
LDC_REG_DATA_CH0
#define LDC_REG_DATA_CH0
LDC description register.
Definition: ldc.h:58
LDC_MANUFACTURER_ID
#define LDC_MANUFACTURER_ID
LDC identification data.
Definition: ldc.h:94
ldc_cfg_t
LDC Click configuration object.
Definition: ldc.h:153