cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER + ADC + DMA

BLima.1
Associate II

I have a STM32F103C8T6 bluepill board. I´m trying to use the Timer3 to TRIGGER the ADC1 conversion + DMA transfer.

The ideia is: when the timer 3 trigger the ADC1, a conversions starts and the dma transfer the result of conversion to a buffer, in circular mode.

I´m using the STMCubeIDE.

In the TIM3 Mode and Configurations, in the tab Parameters Setting, in the field Trigger Output (TRGO) Paramters, i´ve set Trigger Event Selection like Update Event. These settings are shown in the figure below.0693W00000Svu9oQAB.pngNo modo e configuração ADC1 fiz a seguinte configuração.

0693W00000SvuB6QAJ.png0693W00000SvuBfQAJ.png0693W00000SvuBuQAJ.png 

The code:

/* Private variables ---------------------------------------------------------*/

ADC_HandleTypeDef hadc1;

DMA_HandleTypeDef hdma_adc1;

TIM_HandleTypeDef htim3;

/* USER CODE BEGIN PV */

#define Buflen 10

uint16_t dmaBuffer[Buflen];

/* USER CODE END PV */

 /* USER CODE BEGIN 2 */

 HAL_ADCEx_Calibration_Start(&hadc1);

 HAL_TIM_Base_Start(&htim3);

 HAL_ADC_Start_DMA(&hadc1, (uint32_t*)dmaBuffer, Buflen);

 /* USER CODE END 2 */

/* USER CODE BEGIN 4 */

void HAL_ADC_ConvCptCallBack(ADC_HandleTypeDef* hadc){

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);

}

/* USER CODE END 4 */

It's not working. I'm using an oscilloscope to analyse the GPIO PA6. Nothing happens there. The correct would i see a square wave at this port. i.e At each 10 conversions, the pin toggle the status.

What could be? Why it´s no working?

1 ACCEPTED SOLUTION

Accepted Solutions
BLima.1
Associate II

Thanks very much, but it wasn't necessary. I found the unblessed of the mistake. 

The name of the function was written wrong. It was missing a letter.

The Correct: void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc1){

How i´ve written: void HAL_ADC_ConvCptCallback(ADC_HandleTypeDef* hadc1){

View solution in original post

2 REPLIES 2

In debugger, read out and check/post TIM, ADC and DMA registers content.

JW

BLima.1
Associate II

Thanks very much, but it wasn't necessary. I found the unblessed of the mistake. 

The name of the function was written wrong. It was missing a letter.

The Correct: void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc1){

How i´ve written: void HAL_ADC_ConvCptCallback(ADC_HandleTypeDef* hadc1){