请教一下关于ADC,外部EXTI15触发注入通道的问题

2019-03-23 19:01发布

GPIOA.0作为规则通道,GPIOA.1做注入通道,用GPIO.15按键触发注入通道转换。总是进不了中断,总是停在启动文件 B.   ENDP    ALIGN  的地方。 问一下引脚15是不是那么配置? 小弟新手望各神解答啊。GPIOA.0上的ADC转换和DMA是没有问题的。
void RCC_Configuration(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
        RCC_ADCCLKConfig(RCC_PCLK2_Div8);
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
}

void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;       
       
        /*Disable JTAG DEbug*/
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
       
        /*Config InitStructure*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
         /*Set Key Init*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOB, &GPIO_InitStructure);       
}

void ADC1_Configuration(void)
{
        /* Initialize the ADC1 according to the ADC_InitStructure members */
        ADC_InitTypeDef ADC_InitStructure;       
       
        /*Fill ADC InitStrcuture*/
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_InitStructure.ADC_ScanConvMode = ENABLE;
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = 1;    /*Number of Channel of Regular Channels*/
        ADC_Init(ADC1, &ADC_InitStructure);

        /*Regular Group*/
        ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1,ADC_SampleTime_7Cycles5);
       
        /*Injected Group*/
        ADC_InjectedSequencerLengthConfig(ADC1, 1);
        ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 2,ADC_SampleTime_7Cycles5);
        ADC_ExternalTrigInjectedConvConfig(ADC1,ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4);
        ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE);
       
        ADC_AutoInjectedConvCmd(ADC1, DISABLE);
       
        /*Config INTERRUPT of ADC1*/
        ADC_ITConfig(ADC1, ADC_IT_JEOC , ENABLE);

        /*ENABLE DMA of ADC*/
        ADC_DMACmd(ADC1, ENABLE);
        /*ENABLE PERIPH ADC1*/       
        ADC_Cmd(ADC1, ENABLE);
        /*Calibration of ADC*/
        ADC_ResetCalibration(ADC1);
        while( ADC_GetResetCalibrationStatus(ADC1)==SET)
        {
        }
        ADC_StartCalibration(ADC1);
        while(ADC_GetCalibrationStatus(ADC1)==SET)
        {
        }
        /*End Calibration of ADC*/
        /*Start ADC Converting*/
        ADC_SoftwareStartConvCmd(ADC1, ENABLE);       
       
}

void DMA_Configuration(void)
{
        DMA_InitTypeDef DMA_InitStructure;

        /*Config DMA*/
        DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&(ADC1->DR);//ADC1_BASE + 0x4c;
        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_Value;
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
        DMA_InitStructure.DMA_BufferSize = 1;
        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
        DMA_InitStructure.DMA_PeripheralDataSize =
        DMA_PeripheralDataSize_HalfWord;
        DMA_InitStructure.DMA_MemoryDataSize =
        DMA_MemoryDataSize_HalfWord;
        DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
        DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
        DMA_Init(DMA1_Channel1, &DMA_InitStructure);
        /*ENABLE DMA*/
        DMA_Cmd(DMA1_Channel1, ENABLE);
}

void EXTI_Configuration(void)
{                
        EXTI_InitTypeDef EXTI_InitStructure;
        GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource15);
       
        EXTI_InitStructure.EXTI_Line = EXTI_Line15;
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);

}

void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure the Priority Grouping with 1 bit */
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        /* Enable TIM3 global interrupt with Preemption Priority 0 and Sub
        Priority as 2 */
        NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
} 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
lk361115629
1楼-- · 2019-03-24 04:23
/ 没人看一下吗~亲们
youki12345
2楼-- · 2019-03-24 05:56
先不要用DMA吧,试试。对照着例子检查下哪里有不同,是不是那个模块的时钟没开啊
xinjitmzy
3楼-- · 2019-03-24 10:22
 精彩回答 2  元偷偷看……

一周热门 更多>