# Using ADC on STM32

## Software Trigger Polling Mode

Set **External Trigger Conversion Source** to be "Regular Conversion launched by software"

<figure><img src="/files/2O3FWX8IiAnAUeZlbZEn" alt=""><figcaption></figcaption></figure>

```c
HAL_ADC_Start(&hadc1);
HAL_StatusTypeDef status = HAL_ADC_PollForConversion(&hadc1, 100);
uint32_t value = (int32_t)HAL_ADC_GetValue(&hadc1);
```

## Timer Triggered Mode

It is more convenient to use injected channel.

<figure><img src="/files/e8mhRWyIdpxPz9IuTcGr" alt=""><figcaption></figcaption></figure>

Configure Timer 2 to generate reset event on TRGO at 1 kHz.

The 1 kHz is calculated from `APB1_TIMER_CLOCKS / (PSC + 1) / (ARR + 1)`:

$$
\frac{80 MHz}{(79 + 1) \times (999 + 1)} = 1 kHz
$$

<figure><img src="/files/TqSG6iOrLeUJGCV4Mrvp" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tk233.gitbook.io/notes/stm32/analog/adc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
