问题1: 配置完ADC1与DMA后,通道0-3 正常使用(对应IO口为PA0-PA3),但是通道4-7不能使用(对应IO口PA4-7)配置代码如下:
问题2(无代码):无意间发现不配置ADC相应IO口也能读取ADC采集回来的信息,这是怎么回事?验证过了,把IO配置注释掉依旧能用。
void adc_init(void)
{
ADC_InitTypeDef adc;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
ADC_DeInit(ADC1);
adc.ADC_Mode = ADC_Mode_Independent;
adc.ADC_ContinuousConvMode = ENABLE;
adc.ADC_DataAlign = ADC_DataAlign_Right;
adc.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
adc.ADC_NbrOfChannel = CH_NUM ;
adc.ADC_ScanConvMode = ENABLE;
ADC_Init(ADC1,&adc);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_239Cycles5);//PA0
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_239Cycles5);//PA1
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_239Cycles5);//PA2
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_239Cycles5);//PA3
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 5, ADC_SampleTime_239Cycles5);//PA4
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 6, ADC_SampleTime_239Cycles5);//PA5
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 7, ADC_SampleTime_239Cycles5);//PA6
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 8, ADC_SampleTime_239Cycles5);//PA7
ADC_DMACmd(ADC1,ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
void adc_dma_init()
{
DMA_InitTypeDef dma;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel1);
dma.DMA_PeripheralBaseAddr = (u32)&(ADC1->DR);
dma.DMA_MemoryBaseAddr = (u32)&AD_value;
dma.DMA_DIR = DMA_DIR_PeripheralSRC;
dma.DMA_M2M = DMA_M2M_Disable;
dma.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
dma.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
dma.DMA_BufferSize = CH_NUM;
dma.DMA_MemoryInc = DMA_MemoryInc_Enable;
dma.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
dma.DMA_Mode = DMA_Mode_Circular;
dma.DMA_Priority = DMA_Priority_High;
DMA_Init(DMA1_Channel1,&dma);
}
void adc_start(void)
{
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA1_Channel1,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>