打印
[应用相关]

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

[复制链接]
694|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
probedog|  楼主 | 2021-12-14 09:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用了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);

}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

376

主题

2009

帖子

3

粉丝