Loading...
Searching...
No Matches
Interface

ADC interface for measuring external analog signals. More...

Data Structures

struct  ADC_Config
 ADC configuration structure. More...
 
struct  ADC_t
 Struct definition for ADC interface. Provides the API handle for consumers to interact with an ADC peripheral instance. More...
 

Enumerations

enum  ADC_Channel {
  ADC_IN0 , ADC_IN1 , ADC_IN2 , ADC_IN3 ,
  ADC_IN4 , ADC_IN5 , ADC_IN6 , ADC_IN7 ,
  ADC_IN8 , ADC_IN9 , ADC_IN10 , ADC_IN11 ,
  ADC_IN12 , ADC_IN13 , ADC_IN14 , ADC_IN15 ,
  ADC_IN16 , ADC_IN17 , ADC_IN18
}
 ADC input channels enumeration. More...
 
enum  ADC_Resolution { ADC_RES_12 , ADC_RES_10 , ADC_RES_8 , ADC_RES_6 }
 ADC conversion resolution enumeration. More...
 
enum  ADC_Align { ADC_ALIGN_RIGHT , ADC_ALIGN_LEFT }
 ADC data alignment enumeration. More...
 
enum  ADC_EocSelect { ADC_EOCS_SEQUENCE , ADC_EOCS_SINGLE }
 ADC End of Conversion (EOC) selection enumeration. More...
 
enum  ADC_SampleTime {
  ADC_SMP_3 , ADC_SMP_15 , ADC_SMP_28 , ADC_SMP_56 ,
  ADC_SMP_84 , ADC_SMP_112 , ADC_SMP_144 , ADC_SMP_480
}
 ADC channel sample time enumeration. More...
 
enum  ADC_SequenceLength {
  ADC_L1 , ADC_L2 , ADC_L3 , ADC_L4 ,
  ADC_L5 , ADC_L6 , ADC_L7 , ADC_L8 ,
  ADC_L9 , ADC_L10 , ADC_L11 , ADC_L12 ,
  ADC_L13 , ADC_L14 , ADC_L15 , ADC_L16
}
 ADC regular channel sequence length enumeration. More...
 
enum  ADC_Prescale { ADC_ADCPRE_PCLK2_DIV2 , ADC_ADCPRE_PCLK2_DIV4 , ADC_ADCPRE_PCLK2_DIV6 , ADC_ADCPRE_PCLK2_DIV8 }
 ADC prescaler selection enumeration. More...
 
enum  ADC_ConversionType { ADC_CONVERSION_REGULAR , ADC_CONVERSION_INJECTED }
 ADC conversion type enumeration. More...
 

Functions

ADC_t ADC_init (ADC_TypeDef *adc_regs, ADC_Config *config)
 
bool ADC_startConversion (ADC_t *adc, ADC_ConversionType type)
 Starts a regular ADC conversion.
 
uint16_t ADC_readData (ADC_t *adc)
 Reads the data from the last ADC regular conversion.
 
bool ADC_updateConfig (ADC_t *adc, ADC_Config *config)
 Update ADC peripheral configuration.
 

Detailed Description

ADC interface for measuring external analog signals.


Data Structure Documentation

◆ ADC_Config

struct ADC_Config

ADC configuration structure.

Holds all configurable parameters for the ADC peripheral. This structure is used to initialize or update the ADC settings.

Definition at line 296 of file adc.h.

Data Fields
ADC_Resolution RES Resolution of the ADC (CR1.RES).
bool AWDEN Analog Watchdog Enable on regular channels (CR1.AWDEN).
bool JAWDEN Analog Watchdog Enable on injected channels (CR1.JAWDEN).
bool EOCIE Interrupt Enable for End Of regular Conversion (CR1.EOCIE).
bool AWDIE Interrupt Enable for Analog Watchdog (CR1.AWDIE).
bool JEOCIE Interrupt Enable for End Of Injected Conversion (CR1.JEOCIE).
bool AWDSGL Analog Watchdog on single channel (true) or all (false) (CR1.AWDSGL).
bool SCAN Scan mode enable for regular channels (CR1.SCAN).
ADC_Channel AWDCH Analog Watchdog Channel Select (if AWDSGL is true) (CR1.AWDCH).
ADC_Align ALIGN Data alignment (CR2.ALIGN).
ADC_EocSelect EOCS End Of Conversion Selection (CR2.EOCS).
bool DMA Direct Memory Access mode enable for regular channels (CR2.DMA).
bool CONT Continuous conversion mode for regular channels (CR2.CONT).
ADC_SampleTime SMP[19] Sampling time for each channel (0-18) (SMPR1, SMPR2).
uint16_t HTR Analog watchdog higher threshold (HTR). Value should be 12-bit.
uint16_t LTR Analog watchdog lower threshold (LTR). Value should be 12-bit.
ADC_SequenceLength L Regular channel sequence length (1 to 16 conversions) (SQR1.L).
ADC_Channel SQ[16] Regular channel sequence definition (SQ1 to SQ16) (SQR1, SQR2, SQR3).
ADC_SequenceLength JL Injected channel sequence length (1 to 4 conversions) (JSQR.JL).
ADC_Channel JSQ[4] Injected channel sequence definition (JSQ1 to JSQ4) (JSQR).
bool TSVREFE Temperature sensor and VREFINT enable (ADC_CCR.TSVREFE).
bool VBATE VBAT channel enable (ADC_CCR.VBATE).
ADC_Prescale ADCPRE ADC prescaler for ADCCLK (ADC_CCR.ADCPRE).

◆ ADC_t

struct ADC_t

Struct definition for ADC interface. Provides the API handle for consumers to interact with an ADC peripheral instance.

Definition at line 326 of file adc.h.

Data Fields
ADC_TypeDef * interface Pointer to the STM32 ADC peripheral register map (e.g., ADC1).
ADC_Config config Current configuration of the ADC peripheral.
bool(*)(struct _ADC *adc, ADC_Config *config) updateConfig Function pointer to update the ADC configuration.
See also
ADC_updateConfig
bool(*)(struct _ADC *adc, ADC_ConversionType type) startConversion Function pointer to start an ADC conversion (regular or injected).
See also
ADC_startConversion
uint16_t(*)(struct _ADC *adc) readData Function pointer to read the ADC regular conversion result.
See also
ADC_readData

Enumeration Type Documentation

◆ ADC_Channel

ADC input channels enumeration.

Defines the available analog input channels for the ADC.

Enumerator
ADC_IN0 

Analog input channel 0.

ADC_IN1 

Analog input channel 1.

ADC_IN2 

Analog input channel 2.

ADC_IN3 

Analog input channel 3.

ADC_IN4 

Analog input channel 4.

ADC_IN5 

Analog input channel 5.

ADC_IN6 

Analog input channel 6.

ADC_IN7 

Analog input channel 7.

ADC_IN8 

Analog input channel 8.

ADC_IN9 

Analog input channel 9.

ADC_IN10 

Analog input channel 10.

ADC_IN11 

Analog input channel 11.

ADC_IN12 

Analog input channel 12.

ADC_IN13 

Analog input channel 13.

ADC_IN14 

Analog input channel 14.

ADC_IN15 

Analog input channel 15.

ADC_IN16 

Analog input channel 16.

ADC_IN17 

Analog input channel 17.

ADC_IN18 

Analog input channel 18.

Definition at line 177 of file adc.h.

◆ ADC_Resolution

ADC conversion resolution enumeration.

Defines the number of bits for the ADC conversion result. Higher resolution provides more precise measurements but may take longer.

Enumerator
ADC_RES_12 

12-bit resolution

ADC_RES_10 

10-bit resolution

ADC_RES_8 

8-bit resolution

ADC_RES_6 

6-bit resolution

Definition at line 204 of file adc.h.

◆ ADC_Align

enum ADC_Align

ADC data alignment enumeration.

Defines how the ADC conversion data is aligned within the 16-bit data register.

Enumerator
ADC_ALIGN_RIGHT 

Data is right-aligned in the ADC_DR register.

ADC_ALIGN_LEFT 

Data is left-aligned in the ADC_DR register.

Definition at line 215 of file adc.h.

◆ ADC_EocSelect

ADC End of Conversion (EOC) selection enumeration.

Defines when the EOC (End Of Conversion) status flag is set.

Enumerator
ADC_EOCS_SEQUENCE 

EOC flag is set at the end of a sequence of regular conversions.

ADC_EOCS_SINGLE 

EOC flag is set at the end of each single regular conversion.

Definition at line 224 of file adc.h.

◆ ADC_SampleTime

ADC channel sample time enumeration.

Defines the duration for which the input voltage is sampled by the ADC. Expressed in number of ADCCLK cycles. Longer sample times can improve accuracy for high impedance sources.

Enumerator
ADC_SMP_3 

3 ADC clock cycles

ADC_SMP_15 

15 ADC clock cycles

ADC_SMP_28 

28 ADC clock cycles

ADC_SMP_56 

56 ADC clock cycles

ADC_SMP_84 

84 ADC clock cycles

ADC_SMP_112 

112 ADC clock cycles

ADC_SMP_144 

144 ADC clock cycles

ADC_SMP_480 

480 ADC clock cycles

Definition at line 235 of file adc.h.

◆ ADC_SequenceLength

ADC regular channel sequence length enumeration.

Defines the number of conversions in the regular channel group sequence. The value (e.g., ADC_L1 for 1 conversion) directly corresponds to the SQR1.L field value. ADC_L1 means 1 conversion, ADC_L16 means 16 conversions.

Enumerator
ADC_L1 

1 conversion in the regular sequence

ADC_L2 

2 conversions in the regular sequence

ADC_L3 

3 conversions in the regular sequence

ADC_L4 

4 conversions in the regular sequence

ADC_L5 

5 conversions in the regular sequence

ADC_L6 

6 conversions in the regular sequence

ADC_L7 

7 conversions in the regular sequence

ADC_L8 

8 conversions in the regular sequence

ADC_L9 

9 conversions in the regular sequence

ADC_L10 

10 conversions in the regular sequence

ADC_L11 

11 conversions in the regular sequence

ADC_L12 

12 conversions in the regular sequence

ADC_L13 

13 conversions in the regular sequence

ADC_L14 

14 conversions in the regular sequence

ADC_L15 

15 conversions in the regular sequence

ADC_L16 

16 conversions in the regular sequence

Definition at line 252 of file adc.h.

◆ ADC_Prescale

ADC prescaler selection enumeration.

Defines the division factor for the ADC clock (ADCCLK) derived from PCLK2.

Enumerator
ADC_ADCPRE_PCLK2_DIV2 

ADCCLK = PCLK2 divided by 2.

ADC_ADCPRE_PCLK2_DIV4 

ADCCLK = PCLK2 divided by 4.

ADC_ADCPRE_PCLK2_DIV6 

ADCCLK = PCLK2 divided by 6.

ADC_ADCPRE_PCLK2_DIV8 

ADCCLK = PCLK2 divided by 8.

Definition at line 275 of file adc.h.

◆ ADC_ConversionType

ADC conversion type enumeration.

Specifies whether to start a regular or an injected conversion.

Enumerator
ADC_CONVERSION_REGULAR 

Start a regular group conversion.

ADC_CONVERSION_INJECTED 

Start an injected group conversion.

Definition at line 286 of file adc.h.

Function Documentation

◆ ADC_init()

ADC_t ADC_init ( ADC_TypeDef * interface,
ADC_Config * config )
Parameters
interface
config
Returns
spi

Definition at line 23 of file adc.c.

◆ ADC_startConversion()

bool ADC_startConversion ( ADC_t * adc,
ADC_ConversionType type )

Starts a regular ADC conversion.

Sets the SWSTART (or JWSTART) bit in ADC_CR2 register to begin a conversion for the regular group. For continuous mode, this starts the sequence. For single mode, it starts one conversion.

Parameters
adcPointer to the ADC_t handle.
Returns
void

Definition at line 170 of file adc.c.

◆ ADC_readData()

uint16_t ADC_readData ( ADC_t * adc)

Reads the data from the last ADC regular conversion.

Polls the EOC (End Of Conversion) flag and then returns the content of the ADC_DR register.

Parameters
adcPointer to the ADC_t handle.
Returns
The ADC conversion data.

Definition at line 201 of file adc.c.

◆ ADC_updateConfig()

bool ADC_updateConfig ( ADC_t * adc,
ADC_Config * config )

Update ADC peripheral configuration.

Uses the provided configuration to update the ADC registers As with initialisation, passing NULL will set the default config.

Parameters
adcPointer to ADC_t struct.
Returns
NULL.

Definition at line 225 of file adc.c.