初中生
最后登录1970-1-1
在线时间 小时
注册时间2017-8-4
|
本帖最后由 q370375662 于 2017-11-15 13:26 编辑
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* Enable the HSI for the ADC operations */
RCC_HSICmd(ENABLE);
ADC_DeInit(ADC1);
/* ADC1 configuration ------------------------------------------------------*/
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
// ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigInjecConvEdge_Rising; // rising trig conv
ADC_InitStructure.ADC_ExternalTrigConvEdge=ADC_ExternalTrigInjecConvEdge_None;
// ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigInjecConv_T4_CC3; //′¥·¢·½ê½,TIM4 CC3
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel9 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_384Cycles);// PA3===>ADC_Channel_3
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_384Cycles);// PA3===>ADC_Channel_3
/* Enable the request after last transfer for DMA Circular mode */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Wait until the ADC1 is ready */
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
{
}
/*Start ADC1 Software Conversion*/
ADC_SoftwareStartConv(ADC1);
}
void DMA_Configuration()
{
DMA_InitTypeDef DMA_InitStructure;
/* Enable DMA1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* DMA1 channel1 configuration ---------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC_ConvertedValueX;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* Enable the DMA1 Channel1 Transfer complete interrupt */
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
}
我想请问下,如果第一个通道要实时检测,而第二个通道要有脉冲过来再检测请问怎么处理?
|
|