如题,我选用的是ADC的规则同步传输模式ADC_TripleMode_RegSimult,ADC的DMA模式选用的是2型(根据资料,1型是ADC1,2,3一个个采然后一个个DMA传输,而三型是只能传输8位或者6位的数据,因此只能选择二型),根据手册,ADC1,2,3的数据应该是轮流出现在ADC->CDR寄存器的高低16位,也就是说第一次采集时,应该是低16位是ADC1的数据,高16位应该是ADC2的数据;在测试过程中低16位读取的数据是对的,但是高16位一直不对,请问是为啥?还是我有关ADC和DMA的模式选择不对吗?
代码如下:
void Adc_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; ADC_CommonInitTypeDefADC_CommonInitStructure; ADC_InitTypeDef ADC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3,ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL ; GPIO_Init(GPIOF, &GPIO_InitStructure);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2,DISABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,DISABLE);
ADC_CommonInitStructure.ADC_Mode=ADC_TripleMode_RegSimult; ADC_CommonInitStructure.ADC_TwoSamplingDelay= ADC_TwoSamplingDelay_5Cycles; ADC_CommonInitStructure.ADC_DMAAccessMode= ADC_DMAAccessMode_2; ADC_CommonInitStructure.ADC_Prescaler =ADC_Prescaler_Div4; ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution =ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode =ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign =ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 3; ADC_Init(ADC1, &ADC_InitStructure); ADC_Init(ADC2, &ADC_InitStructure);
ADC_DMACmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); ADC_DMACmd(ADC2, ENABLE); ADC_Cmd(ADC2, ENABLE); ADC_DMACmd(ADC3, ENABLE); ADC_Cmd(ADC3, ENABLE);
ADC_RegularChannelConfig(ADC1,ADC_Channel_0, 1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC1,ADC_Channel_1, 2, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC1,ADC_Channel_4, 3, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2,ADC_Channel_10, 1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2,ADC_Channel_11, 2, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2,ADC_Channel_12, 3, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_4, 1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_5, 2, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_6, 3, ADC_SampleTime_3Cycles);
ADC_SoftwareStartConv(ADC1); ADC_SoftwareStartConv(ADC2); ADC_SoftwareStartConv(ADC3); }
MYDMA_Config(DMA2_Stream0,DMA_Channel_0,(u32)&ADC->CDR,(u32)&adcx,144); MYDMA_Enable(DMA2_Stream0,144);
直接加我QQ吧1747771947
....我也没用过串口看波形啊,我只会采数据
一周热门 更多>