本帖最后由 SevenSun 于 2023-2-17 09:17 编辑
有人碰到过N32G452 使用ADC+DMA 无法进入DMA 中断问题吗
配置代码如下
//Config ADC io PA4
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA,
ENABLE);
GPIO_InitType GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_PIN_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA1,ENABLE);
//Config DMA channel
DMA_InitType DMA_InitStructure;
DMA_DeInit(DMA1_CH8);
DMA_InitStructure.PeriphAddr = (uint32_t)&ADC2->DAT;
DMA_InitStructure.MemAddr = (uint32_t)ADC_SourceData;
DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC;
DMA_InitStructure.BufSize = 1;
DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE;
DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD;
DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR;
DMA_InitStructure.Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE;
DMA_Init(DMA1_CH8, &DMA_InitStructure);
DMA_EnableChannel(DMA1_CH8, ENABLE);
NVIC_InitType NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel8_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ClrIntPendingBit(DMA1_INT_TXC8,DMA1);
DMA_ConfigInt(DMA1_CH8,DMA_INT_TXC,ENABLE);
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC2,ENABLE);
//Config ADC2 ch1
ADC_InitType ADC_InitStructure;
ADC_InitStructure.WorkMode = ADC_WORKMODE_INDEPENDENT;
ADC_InitStructure.MultiChEn = DISABLE;
ADC_InitStructure.ContinueConvEn = DISABLE;
ADC_InitStructure.ExtTrigSelect = ADC_EXT_TRIGCONV_T3_TRGO;
ADC_InitStructure.DatAlign = ADC_DAT_ALIGN_R;
ADC_InitStructure.ChsNumber = 1;
ADC_Init(ADC2, &ADC_InitStructure);
ADC_ConfigRegularChannel(ADC2, ADC2_Channel_01_PA4, 1, ADC_SAMP_TIME_55CYCLES5);
ADC_EnableDMA(ADC2,ENABLE);
ADC_Enable(ADC2, ENABLE);
/*Check ADC Ready*/
while(ADC_GetFlagStatusNew(ADC2,ADC_FLAG_RDY) == RESET);
/* Start ADC2 calibration */
ADC_StartCalibration(ADC2);
/* Check the end of ADC2 calibration */
while (ADC_GetCalibrationStatus(ADC2));
ADC_EnableExternalTrigConv(ADC2, ENABLE);
TIM_TimeBaseInitType TIM_TimeBaseStructure;
RCC_ClocksType RCC_ClockFreq;
RCC_GetClocksFreqValue(&RCC_ClockFreq);
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE);
TIM_InitTimBaseStruct(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.Period = 100 - 1;
TIM_TimeBaseStructure.Prescaler = (RCC_ClockFreq.Pclk1Freq / 1000000) - 1;
TIM_TimeBaseStructure.ClkDiv = 0;
TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure);
TIM_SelectOutputTrig(TIM3,TIM_TRGO_SRC_UPDATE);
TIM_Enable(TIM3, ENABLE);
|