我正在使用 3 个由
tiM3 触发的 ADC 模块同时启动。
我在 DMAx_Channely_IRQHandler 函数中读取了结果,仅为了调试,我在 GPIO 中进行了切换。
我有 3 个 DMAx_Channely_IRQHandler 函数,一个用于每个带 DMA 的 ADC 和 3 个我切换的输出品脱
所有输出都显示 DMAx_Channely_IRQHandler 函数被调用了两次。
我正在使用带有 HAL 的
STM32G474 和 STM32CubeIDE。
为什么会发生这种情况,我该如何解决?
谢谢!!
- HAL_ADC_Start_DMA(&hadc1, (uint32_t *)data_ADC_1, N_CH);
- HAL_ADC_Start_DMA(&hadc2, (uint32_t *)data_ADC_2, N_CH);
- HAL_ADC_Start_DMA(&hadc3, (uint32_t *)data_ADC_3, N_CH);
- ---------------
- static void MX_DMA_Init(void)
- {
- /* DMA controller clock enable */
- __HAL_RCC_DMAMUX1_CLK_ENABLE();
- __HAL_RCC_DMA2_CLK_ENABLE();
- __HAL_RCC_DMA1_CLK_ENABLE();
- /* DMA interrupt init */
- /* DMA1_Channel2_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
- /* DMA1_Channel3_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
- /* DMA2_Channel1_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn);
- }
- -------------
- static void MX_ADC1_Init(void)
- {
- /* USER CODE BEGIN ADC1_Init 0 */
- /* USER CODE END ADC1_Init 0 */
- ADC_MultiModeTypeDef multimode = {0};
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC1_Init 1 */
- /* USER CODE END ADC1_Init 1 */
- /** Common config
- */
- hadc1.Instance = ADC1;
- hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc1.Init.Resolution = ADC_RESOLUTION_12B;
- hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
- hadc1.Init.GainCompensation = 0;
- hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
- hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
- hadc1.Init.LowPowerAutoWait = DISABLE;
- hadc1.Init.ContinuousConvMode = DISABLE;
- hadc1.Init.NbrOfConversion = 3;
- hadc1.Init.DiscontinuousConvMode = DISABLE;
- hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T3_TRGO;
- hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
- hadc1.Init.DMAContinuousRequests = ENABLE;
- hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc1.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the ADC multi-mode
- */
- multimode.Mode = ADC_MODE_INDEPENDENT;
- if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_1;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Rank = ADC_REGULAR_RANK_2;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Rank = ADC_REGULAR_RANK_3;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC1_Init 2 */
- /* USER CODE END ADC1_Init 2 */
- }
- -----------
- void DMA1_Channel2_IRQHandler(void)
- {
- /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
- /* USER CODE END DMA1_Channel2_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_adc2);
- /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
- adc22_cnt++;
- data_adc2 = data_ADC_2[0];
- HAL_GPIO_TogglePin(END_CONV_2_GPIO_Port, END_CONV_2_Pin);
- /* USER CODE END DMA1_Channel2_IRQn 1 */
- }