Skip to content

devcoons/stm32-drv-adc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ADC DRIVER

ADC driver reusable in different platforms. For DMA mode only.

Supported Hardware

  • [PSU]
  • [supported]
  • [supported]

Functions Guide

  • adc_initialize: initializes the ADC conversion.
  • adc_deinitialize: deinitializes the ADC conversion.
  • adc_get_value: starts the conversion.
  • stop_adc:stops the conversion.

How to use

  • Set the ADC peripheral in the .ioc file
  • Include the header file drv_adc.h
  • Copy the drv_adc_config.h.template in a parent folder, rename it to drv_adc_config.h and modify it accordingly.
  • Create the adc_t instances. 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 an ADC_input (defined in the configuration file).

Example

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);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages