ADC driver reusable in different platforms. For DMA mode only.
- [PSU]
- [supported]
- [supported]
adc_initialize: initializes the ADC conversion.adc_deinitialize: deinitializes the ADC conversion.adc_get_value: starts the conversion.stop_adc:stops the conversion.
- Set the ADC peripheral in the .ioc file
- Include the header file
drv_adc.h - Copy the
drv_adc_config.h.templatein a parent folder, rename it todrv_adc_config.hand modify it accordingly. - Create the
adc_tinstances. The following members of the structure must be defined:instance.value: address for the converted value.instance.dma_storage_sz: DMA storage size.instance.max_adc_channels: maximum number of ADC channels you want to use.instance.handler: handler of choice (ex. hadc1).instance.mx_init: ADC initializing function generated by the configuration tool.
- Use the function:
-
adc_initialize()To start the conversion and save the converted value.adc_get_value()To retrieve the values of anADC_input(defined in the configuration file).
Let's consider a NUCLEO - L552ZE-Q. ADC1 has been enabled in the .ioc file.
- Define the inputs enum in the configuration file
/*!
@file drv_adc_config.h
*/
/******************************************************************************
* Preprocessor Definitions & Macros
******************************************************************************/
#define ENUM_ADC_Input
typedef enum
{
ADC_V12A_MEAS = 0x10,
ADC_V12B_MEAS = 0x11,
}ADC_Input;
/******************************************************************************
* EOF - NO CODE AFTER THIS LINE
******************************************************************************/- Create the ADC handler
adc_t adc1 = {.mx_init = MX_ADC1_Init , .dma_storage_sz = 100, .handler = &hadc1, .max_adc_channels = 4};- Initialize the handler
adc_initialize(&adc1);- Retrieve the specified value
uint16_t value;
adc_get_value(&adc1, ADC_V12A_MEAS, &value);