Author Topic: STM32 : ADC with DMA and Timer  (Read 467 times)

0 Members and 1 Guest are viewing this topic.

Offline gab_22Topic starter

  • Contributor
  • Posts: 10
  • Country: fr
STM32 : ADC with DMA and Timer
« on: June 06, 2023, 08:09:05 pm »
Hi!
I'm trying to convert 4 ADC channels with interrupt and DMA on my STM32 dev board (nucleo F303RE) the goal is to start a conversion periodically and transfer the results through the DMA. But unfortunately, it doesn't work :(

Here is the configuration, I use STM32CubeIDE.

ADC Conf





TIM4 Conf


And here my code
Code: [Select]
/* USER CODE BEGIN PV */
uint16_t raw[4];
uint8_t ADDCPLT = 0;
/* USER CODE END PV */

Code: [Select]
/* USER CODE BEGIN 2 */
  HAL_ADC_Start_DMA(&hadc1, (uint16_t)*raw, 4);
  HAL_TIM_Base_Start_IT(&htim4);
  /* USER CODE END 2 */

main loop
Code: [Select]
while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  if(ADDCPLT)
  {
  HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
  ADDCPLT = 0;
  }
  }
  /* USER CODE END 3 */

Code: [Select]
/* USER CODE BEGIN 4 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance == ADC1)
{
ADDCPLT = 255;
}
}
/* USER CODE END 4 */

When I start the program on the target, I see LD2 blinking at ~10Hz as expected, but I don't see anything in raw[4] variables. (checked with STM32CubeIDE integrated debugger) I think I forgot something somewhere... Do you have any ideas?
Thanks
 

Offline Georgy.Moshkin

  • Regular Contributor
  • *
  • Posts: 146
  • Country: hk
  • R&D Engineer
    • Electronic projects, modules and courses on Arduino and STM32
Re: STM32 : ADC with DMA and Timer
« Reply #1 on: June 07, 2023, 02:07:51 am »
I think it should be
Code: [Select]
HAL_ADC_Start_DMA(&hadc1, (uint16_t*)&raw, 4);And check this:
Code: [Select]
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init(); // <-- this should be placed before MX_ADC_Init()
MX_ADC1_Init(); // <-- this should be placed after MX_DMA_Init()
...

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf