*以下为ADC触发*/
/* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = BufferSize-1; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter=0; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 channel2 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 8; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OC2Init(TIM2, &TIM_OCInitStructure);
TIM_SelectMasterSlaveMode(TIM8,TIM_MasterSlaveMode_Enable);// 主从模式 TIM_SelectSlaveMode(TIM2,TIM_SlaveMode_External1); //从模式 上升沿作为计数脉冲 TIM_ITRxExternalClockConfig(TIM2,TIM_TS_ITR1);
/* DMA1 Channel1 Configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_1RegularConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //外设作为源 DMA_InitStructure.DMA_BufferSize =32; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/ ADC_DeInit(ADC1); ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //ADC1 and ADC2 为同步规则模式 ADC_InitStructure.ADC_ScanConvMode = DISABLE; //单通道模式 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //循换模式 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_1Cycles5); ADC_DMACmd(ADC1, ENABLE);
// /* ADC2 configuration ------------------------------------------------------*/ ADC_DeInit(ADC2); ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC2, &ADC_InitStructure); ADC_RegularChannelConfig(ADC2, ADC_Channel_14, 1, ADC_SampleTime_1Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1));
/* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 reset calibaration register */ ADC_ResetCalibration(ADC2); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC2 calibaration */ ADC_StartCalibration(ADC2); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC2));
ADC_SoftwareStartConvCmd(ADC1, ENABLE); TIM_CtrlPWMOutputs(TIM2, ENABLE); TIM_Cmd(TIM8, ENABLE); TIM_Cmd(TIM2, ENABLE); DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); 双ADC无法完成采集,也无法跳DMA中断,不知道什么原因,触发时钟没有问题,就是无法完成AD转换啊。我是利用TIM2_CC2触发的,已经将ADC1设置为TIM2_CC2触发,ADC2为软件触发。ADC时钟使能,ADC端口都已经设置好了。
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_GPIOC, ENABLE);
/* 103通道对应io口列表
ADIN0:PA0;ADIN1:PA1;ADIN2:PA2;ADIN3:PA3;ADIN4:PA4;ADIN5:PA5;ADIN6:PA6;ADIN7:PA7;
ADIN8:PB0;ADIN9:PB1;
ADIN10:PC0;ADIN11:PC1;ADIN12:PC2;ADIN13:PC3;ADIN14:PC4;ADIN15:PC5;
*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&ADC1->DR);
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DMA_ADC_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = ADC_BUFFER_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
// ADC_DiscModeChannelCountConfig(ADC1,4); //四个以后停止
// ADC_DiscModeCmd(ADC1,ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //扫描或单次
ADC_InitStructure.ADC_ContinuousConvMode = ADC_CONTNUOUS_MODE; //连续
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //对齐
ADC_InitStructure.ADC_NbrOfChannel = 1; //顺序进行转换的通道数目
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Init(ADC2, &ADC_InitStructure);
ADC_ExternalTrigConvCmd(ADC2, ENABLE); //adc2外触发
//通道设定值1~16
/*
ADC_RegularChannelConfig(ADC1, ADC_GROUP1_CHANNEL1, 1, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC1, ADC_GROUP1_CHANNEL2, 2, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC1, ADC_GROUP1_CHANNEL3, 3, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC2, ADC_GROUP2_CHANNEL1, 1, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC2, ADC_GROUP2_CHANNEL2, 2, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC2, ADC_GROUP2_CHANNEL3, 3, ADC_CHANNEL_SAMPLETIME);
*/
//每通道组重复5次后采集其它通道
ADC_RegularChannelConfig(ADC1, ADC1_OTHER_CHANNEL, 1, ADC_CHANNEL_SAMPLETIME);
ADC_RegularChannelConfig(ADC2, ADC2_OTHER_CHANNEL, 1, ADC_CHANNEL_SAMPLETIME);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
// 自校准
ADC_Cmd(ADC1, ENABLE);
ADC_TempSensorVrefintCmd(ENABLE); //测温内部参考电压
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_Cmd(ADC2, ENABLE);
ADC_ResetCalibration(ADC2);
while(ADC_GetResetCalibrationStatus(ADC2));
ADC_StartCalibration(ADC2);
while(ADC_GetCalibrationStatus(ADC2));
/* Test on DMA1 channel1 transfer complete flag
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1))
ADC_SoftwareStartConvCmd(ADC1, ENABLE);*/
DMA_ClearFlag(DMA1_FLAG_TC1|DMA1_FLAG_HT1|DMA1_FLAG_TE1);
//ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); //中断
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
一周热门 更多>