Skip to main content
FTrom
Associate III
Nov 23, 2021 11:14 AM UTC
Solved

ADC DMA does not work

I m trying to configure the ADC1 in DMA modality with STM32F303K8

when I debug the values does not change at all.

With the breakpoint i could see that DMA1_Channel1_IRQHandler is called.

/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
 
UART_HandleTypeDef huart1;
 
/* USER CODE BEGIN PV */
int32_t enc_value1;
int32_t enc_value2;
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM3_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{
 /* USER CODE BEGIN 1 */
	int32_t Count1=0;
	int32_t Count2=0;
 /* USER CODE END 1 */
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_TIM2_Init();
 MX_TIM3_Init();
 MX_USART1_UART_Init();
 /* USER CODE BEGIN 2 */
 HAL_TIM_Encoder_Start_IT(&htim2, TIM_CHANNEL_ALL);
 HAL_TIM_Encoder_Start_IT(&htim3, TIM_CHANNEL_ALL);
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}
void DMA1_Channel1_IRQHandler(void)
 
{
 
 /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
 
 
 
 /* USER CODE END DMA1_Channel1_IRQn 0 */
 
 HAL_DMA_IRQHandler(&hdma_adc1);
 
 /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
 
 
 
 /* USER CODE END DMA1_Channel1_IRQn 1 */
 
}

This topic has been closed for replies.
Imen.DBest answer
ST Technical Moderator
Nov 23, 2021 1:25 PM UTC

The DMA initialization MX_DMA_Init(); should be before other peripheral initialization.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks

4 replies

ST Technical Moderator
Nov 23, 2021 12:04 PM UTC

Hello @FTrom​ ,

You are missing the DMA initialization MX_DMA_Init(); which should be before other peripheral initialization.

Please try this, then let me know if this solved your issue, if so please "Select as Best" button.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
FTrom
FTromAuthor
Associate III
Nov 23, 2021 12:31 PM UTC

Hi Imen

if I understand correctly I should modify as

 HAL_Init();
 
 SystemClock_Config();
 
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 MX_DMA_Init();
 MX_ADC1_Init();

But unfortunately, the values are stoked as before

Thanks

Imen.DBest answer
ST Technical Moderator
Nov 23, 2021 1:25 PM UTC

The DMA initialization MX_DMA_Init(); should be before other peripheral initialization.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
TDK
Nov 23, 2021 1:14 PM UTC

The code you posted in the OP doesn't initialize the ADC or the DMA.

"If you feel a post has answered your question, please click ""Accept as Solution""."