cancel
Showing results for 
Search instead for 
Did you mean: 

ADC DMA does not work

FTrom
Associate II

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 */
 
}

1 ACCEPTED SOLUTION

Accepted Solutions

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

4 REPLIES 4
Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
FTrom
Associate II

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

TDK
Guru

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".

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen