STM32:模拟看门狗只触发一次中断HAL_ADC_LevelOutOfWindowCallback

Posted

技术标签:

【中文标题】STM32:模拟看门狗只触发一次中断HAL_ADC_LevelOutOfWindowCallback【英文标题】:STM32: analog watchdog does only trigger interrupt HAL_ADC_LevelOutOfWindowCallback once 【发布时间】:2021-06-21 07:07:13 【问题描述】:

问题

是否需要在每次触发模拟看门狗时重置模拟看门狗? 中断还是我的代码有错误? 如果我每次都需要重置它,我该怎么做? 是否有可以在回调中调用的 HAL 函数?

我的代码

主要

HAL_ADC_Start(&hadc2);

ADC 和 WDG 配置

static void MX_ADC2_Init(void)
  ADC_AnalogWDGConfTypeDef AnalogWDGConfig = 0;
  ADC_ChannelConfTypeDef sConfig = 0;

  /** Common config*/
  hadc2.Instance = ADC2;
  hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc2.Init.Resolution = ADC_RESOLUTION_8B;
  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc2.Init.ContinuousConvMode = ENABLE;
  hadc2.Init.DiscontinuousConvMode = DISABLE;
  hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc2.Init.NbrOfConversion = 1;
  hadc2.Init.DMAContinuousRequests = DISABLE;
  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc2.Init.LowPowerAutoWait = DISABLE;
  hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  if (HAL_ADC_Init(&hadc2) != HAL_OK)
  
    Error_Handler();
  
  /** Configure Analog WatchDog 1 */
  AnalogWDGConfig.WatchdogNumber = ADC_ANALOGWATCHDOG_1;
  AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;
  AnalogWDGConfig.HighThreshold = 64-1;
  AnalogWDGConfig.LowThreshold = 0;
  AnalogWDGConfig.Channel = ADC_CHANNEL_1;
  AnalogWDGConfig.ITMode = ENABLE;
  if (HAL_ADC_AnalogWDGConfig(&hadc2, &AnalogWDGConfig) != HAL_OK)
  
    Error_Handler();
  
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
  
    Error_Handler();
  

回调

void HAL_ADC_LevelOutOfWindowCallback (ADC_HandleTypeDef * hadc)
    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);

【问题讨论】:

【参考方案1】:

查看您的代码...特别是...

hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV

你可能只需要在中断后再次调用 start...

HAL_ADC_Start(&hadc2);

【讨论】:

以上是关于STM32:模拟看门狗只触发一次中断HAL_ADC_LevelOutOfWindowCallback的主要内容,如果未能解决你的问题,请参考以下文章

stm32捕获比较中断啥意思

stm32啥触发串口接收中断

stm32窗口看门狗中断服务函数为啥不能用延时函数

STM32F030 定时器多次溢出才触发中断的问题

stm32 无刷驱动

stm32-浅谈中断