adc21  2.1.0.0
Main Page

ADC 21 Click

ADC 21 Click is a compact add-on board that converts an analog voltage into a digital representation. This board features the ADC1283, a low-power, eight-channel pure CMOS 12-bit analog-to-digital converter from STMicroelectronics. The ADC1283 is specified for conversion from 50ksps to 200ksps. Its architecture is based on a successive approximation register with an internal track-and-hold cell. It features eight single-ended multiplexed inputs, where the output serial data is straight binary and SPI-compatible.

Click Product page


Click library

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

Software Support

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

Standard key functions :

Example key functions :

  • adc21_read_raw_adc This function reads raw ADC value from the selected channel by using SPI serial interface.
    err_t adc21_read_raw_adc ( adc21_t *ctx, uint8_t channel, uint16_t *raw_adc );
  • adc21_read_voltage This function reads raw ADC value from the selected channel and converts it to proportional voltage level depending on the avcc selection.
    err_t adc21_read_voltage ( adc21_t *ctx, uint8_t channel, float avcc, float *voltage );

Example Description

This example demonstrates the use of ADC 21 Click board by reading and displaying the voltage levels from 8 analog input channels.

The demo application is composed of two sections :

Application Init

Initializes the driver and logger.

void application_init ( void )
{
log_cfg_t log_cfg;
adc21_cfg_t adc21_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
adc21_cfg_setup( &adc21_cfg );
ADC21_MAP_MIKROBUS( adc21_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == adc21_init( &adc21, &adc21_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Reads the voltage levels from all 8 analog input channels and displays the results on the USB UART once per second approximately.

void application_task ( void )
{
static uint8_t ch_num = ADC21_CHANNEL_0;
float ch_voltage;
if ( ADC21_OK == adc21_read_voltage ( &adc21, ch_num, ADC21_AVCC_3V3, &ch_voltage ) )
{
log_printf ( &logger, " CH%u voltage: %.2f V\r\n", ( uint16_t ) ch_num, ch_voltage );
}
if ( ++ch_num > ADC21_CHANNEL_7 )
{
log_printf ( &logger, " ------------------------\r\n\n" );
ch_num = ADC21_CHANNEL_0;
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.ADC21

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.


ADC21_OK
@ ADC21_OK
Definition: adc21.h:165
adc21_t
ADC 21 Click context object.
Definition: adc21.h:132
adc21_init
err_t adc21_init(adc21_t *ctx, adc21_cfg_t *cfg)
ADC 21 initialization function.
ADC21_CHANNEL_0
#define ADC21_CHANNEL_0
ADC 21 channel selection setting.
Definition: adc21.h:74
application_task
void application_task(void)
Definition: main.c:59
ADC21_MAP_MIKROBUS
#define ADC21_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: adc21.h:118
adc21_read_voltage
err_t adc21_read_voltage(adc21_t *ctx, uint8_t channel, float avcc, float *voltage)
ADC 21 read voltage function.
ADC21_AVCC_3V3
#define ADC21_AVCC_3V3
Definition: adc21.h:88
ADC21_CHANNEL_7
#define ADC21_CHANNEL_7
Definition: adc21.h:81
adc21_cfg_t
ADC 21 Click configuration object.
Definition: adc21.h:145
application_init
void application_init(void)
Definition: main.c:29
adc21_read_raw_adc
err_t adc21_read_raw_adc(adc21_t *ctx, uint8_t channel, uint16_t *raw_adc)
ADC 21 read raw adc function.
adc21_cfg_setup
void adc21_cfg_setup(adc21_cfg_t *cfg)
ADC 21 configuration object setup function.