Electronics > Microcontrollers
STM32 : ADC with DMA and Timer
(1/1)
gab_22:
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
[attachimg=1]
[attachimg=2]
[attachimg=3]
TIM4 Conf
[attachimg=4]
And here my code
--- Code: ---/* USER CODE BEGIN PV */
uint16_t raw[4];
uint8_t ADDCPLT = 0;
/* USER CODE END PV */
--- End code ---
--- Code: ---/* USER CODE BEGIN 2 */
HAL_ADC_Start_DMA(&hadc1, (uint16_t)*raw, 4);
HAL_TIM_Base_Start_IT(&htim4);
/* USER CODE END 2 */
--- End code ---
main loop
--- Code: ---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 */
--- End code ---
--- Code: ---/* USER CODE BEGIN 4 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance == ADC1)
{
ADDCPLT = 255;
}
}
/* USER CODE END 4 */
--- End code ---
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
Georgy.Moshkin:
I think it should be
--- Code: --- HAL_ADC_Start_DMA(&hadc1, (uint16_t*)&raw, 4);
--- End code ---
And check this:
--- Code: ---/* 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()
...
--- End code ---
MasterT:
Check it out:
https://github.com/STMicroelectronics/STM32CubeF3/tree/master/Projects/STM32F303RE-Nucleo/Examples/ADC/ADC_Sequencer
CubeMX has an examples worth to study
Navigation
[0] Message Index
Go to full version