你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

ADC1,ADC2,ADC3,加DMA为什么ADC3回调函数不能正常工作

[复制链接]
ZHANGYONGHAI 提问时间:2021-11-24 08:28 / 未解决

我用了ADC1,ADC2,ADC3,DMA1_Stream0,DMA1_Stream1,BDMA_Channel0,ADC1.ADC2.回调函数都是正常工作,就是ADC3.回调函数不能正常工作。有没有遇到这种情况的 芯片是STM32H750.ADC分频得80MHZ

HAL_RCC_DMA1_CLK_ENABLE(); HAL_RCC_ADC12_CLK_ENABLE(); hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV10; hadc1.Init.Resolution = ADC_RESOLUTION_16B; hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc1.Init.LowPowerAutoWait = DISABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.NbrOfConversion = 0x04U; hadc1.Init.DiscontinuousConvMode = ENABLE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; hadc1.Init.OversamplingMode = DISABLE;

HAL_ADC_Init(&hadc1) ;

HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);

/* Configure the ADC multi-mode / multimode.Mode = ADC_MODE_INDEPENDENT; if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) { Error_Handler(); }

hadc1.Instance = ADC2; hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV10; hadc1.Init.Resolution = ADC_RESOLUTION_16B; hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc1.Init.LowPowerAutoWait = DISABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.NbrOfConversion = 0x04U; hadc1.Init.DiscontinuousConvMode = ENABLE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; hadc1.Init.OversamplingMode = DISABLE;

HAL_ADC_Init(&hadc2) ;

HAL_ADCEx_Calibration_Start(&hadc2, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);

HAL_RCC_BDMA_CLK_ENABLE(); HAL_RCC_ADC3_CLK_ENABLE();

hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV10; hadc3.Init.Resolution = ADC_RESOLUTION_16B; hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE; hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc3.Init.LowPowerAutoWait = DISABLE; hadc3.Init.ContinuousConvMode = ENABLE; hadc3.Init.NbrOfConversion = 0x04U; hadc3.Init.DiscontinuousConvMode = ENABLE; hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED; hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; hadc3.Init.OversamplingMode = DISABLE;

HAL_ADC_Init(&hadc3) ;

HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);

hdma_adc1.Instance = DMA1_Stream0; hdma_adc1.Init.Request = DMA_REQUEST_ADC1; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc1);

__HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); / DMA1_Stream0_IRQn interrupt configuration / HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 4, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);

hdma_adc1.Instance = DMA1_Stream1; hdma_adc1.Init.Request = DMA_REQUEST_ADC2; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc2);

__HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc2); / DMA1_Stream1_IRQn interrupt configuration / HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 4, 1); HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);

hdma_adc3.Instance = BDMA_Channel0; hdma_adc3.Init.Request = BDMA_REQUEST_ADC3; hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc3.Init.MemInc = DMA_MINC_ENABLE; hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc3.Init.Mode = DMA_CIRCULAR; hdma_adc3.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

HAL_DMA_Init(&hdma_adc3) ;

__HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc3); / DMA interrupt init / / BDMA_Channel0_IRQn interrupt configuration / HAL_NVIC_SetPriority(BDMA_Channel0_IRQn, 4, 2); HAL_NVIC_EnableIRQ(BDMA_Channel0_IRQn);

/**

  • @brief Conversion complete callback in non blocking mode
  • @param hadc ADC handle
  • @retval None */

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {

        if(hadc->Instance == ADC1)
        {

                SCB_InvalidateDCache_by_Addr(Adc1Value,ADC_AVERAGE_SIZE);
                printf(" ADC00000: \r\n");
        }
        else if(hadc->Instance == ADC2)
        {
                SCB_InvalidateDCache_by_Addr(Adc2Value,ADC_AVERAGE_SIZE);

                printf(" ADC11111: \r\n");
        }
        else if(hadc->Instance == ADC3)
   {
                SCB_InvalidateDCache_by_Addr(Adc3Value,ADC_AVERAGE_SIZE);

                printf(" ADC22222: \r\n");

        }      

}

void DMA1_Stream0_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_adc1); }

void DMA1_Stream1_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_adc2); }

/**

  • @brief This function handles BDMA channel0 global interrupt. */ void BDMA_Channel0_IRQHandler(void) {

HAL_DMA_IRQHandler(&hdma_adc3);

}

收藏 评论1 发布时间:2021-11-24 08:28

举报

1个回答
ZHANGYONGHAI 回答时间:2021-12-6 09:52:08

芯片是STM32H750VBT6.ADC分频得30 就是ADC3.回调函数不能正常工作,ADC1,ADC3回调函数能正常工作;

QQ截图20211206094501.png

QQ截图20211206094542.png

QQ截图20211206095006.png

所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版