一个通道采样10次,采集到数据是 FFF FFF B56 FFF FFF B53 FFF FFF B4D FFF
求帮忙看看代码
[mw_shl_code=c,true]u16 AD_Vaule[3][10]; //DMA½ÓÊÕ»º´æ 3¸öÊýÖµ
#define ADC_DR_Address 0x4001244C //ADC1 ÄÚ´æ»ùµØÖ·
#define DMA1_MEM_LEN sizeof(AD_Vaule) // »º´æÆ÷µÄ´óС
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); //DMA¹ÒÔÚAHB×ÜÏßÏÂ
DMA_DeInit(DMA1_Channel1);//½«DMA1 ͨµÀ1µÄÖµÉèÖÃΪȱʡֵ
//ÐèÒªµÈ´ýDMA1ʱÖÓÎȶ¨
__nop();
__nop();
DMA_InitStructure.DMA_BufferSize=30; //DMA»º´æÆ÷´óС
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC; //ÍâÉè×÷Ϊ»ùµØÖ·
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
DMA_InitStructure.DMA_MemoryBaseAddr= (u32)AD_Vaule; //ÄÚ´æ»ùµØÖ·
DMA_InitStructure.DMA_MemoryDataSize= DMA_MemoryDataSize_HalfWord; // °ë×Ö 16λ
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable; //ÄÚ´æµØÖ·ÔöÁ¿Ä£Ê½
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular; //Ñ­»·Ä£Ê½
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)(&ADC1->DR); //ÍâÉè»ùµØÖ·
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord ; //°ë×Ö16λ
DMA_InitStructure.DMA_PeripheralInc= DMA_PeripheralInc_Disable ; //ÍâÉèµØÖ· ·ÇÔöÁ¿Ä£Ê½
DMA_InitStructure.DMA_Priority= DMA_Priority_High; //ÖеÈÓÅÏȼ¶Ä£Ê½
DMA_Init(DMA1_Channel1,&DMA_InitStructure); //DMAͨµÀ
DMA_Cmd(DMA1_Channel1,ENABLE); //¿ªÆôDMA1ͨµÀ
}[/mw_shl_code]
[mw_shl_code=c,true]void ADC_INIT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1,ENABLE);//³õʼ»¯GPIOA¡¢ADC1ʱÖÓ
//ÉèÖÃ
A1ΪģÄâÊäÈë
// RCC_ADCCLKConfig(RCC_PCLK2_Div6);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2; //ÅäÖÃ
A0 PA1 PA2 PA3Ä£Äâ
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//ÅäÖÃADC1
//ÉèÖÃADC·ÖƵʱÖÓ£¬ADCʱÖÓ²»Äܳ¬¹ý14MHz
ADC_DeInit(ADC1);
//ÅäÖÃADC1²ÎÊý
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE; //ADCÁ¬Ðøģʽ¿ª
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; //12λÊý¾ÝÓÒ¶ÔÆë
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; //Íⲿ¿ªÆô¹Ø ÓÉÈí¼þ¿ªÆô
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent; //ADC¹¤×÷ÔÚ¶ÀÁ¢Ä£Ê½
ADC_InitStructure.ADC_NbrOfChannel=3; //¿ªÆôͨµÀÊýΪ1
ADC_InitStructure.ADC_ScanConvMode=ENABLE; //ɨÃèģʽ¹Ø
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_55Cycles5); //ÅäÖùæÔò×éͨµÀ£¬ÉèÖÃͨµÀµÄ˳Ðò£¬²ÉÑùʱ¼ä
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,2,ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_2,3,ADC_SampleTime_55Cycles5);
ADC_Cmd(ADC1,ENABLE);
ADC_DMACmd(ADC1,ENABLE); //ʹÄÜADC1--DMAÇëÇó
//¿ªÆôADCУ׼£¬±ØÐ뿪!
ADC_ResetCalibration(ADC1); //ʹÄܸ´Î»Ð£×¼
while(ADC_GetResetCalibrationStatus(ADC1)); //µÈ´ý¸´Î»Ð£×¼½áÊø
ADC_StartCalibration(ADC1); //¿ªÆôADУ׼
while(ADC_GetCalibrationStatus(ADC1)); //µÈ´ýУ׼½áÊø
ADC_SoftwareStartConvCmd(ADC1,ENABLE); //Èí¼þת»»
}[/mw_shl_code][mw_shl_code=c,true] while(1)
{
u8 t,i;
for(t=0;t<3;t++)
{
AD_Vaule_Average[t]=0;
for(i=0;i<10;i++) //Çó¸öͨµÀ10´ÎµÄƽ¾ùÖµ
{
AD_Vaule_Average[t]+=AD_Vaule[t]
;
}
AD_Vaule_Average[t]/=10;
}
for(t=0;t<3;t++) //ÒÀ´ÎÏÔʾ
{
// printf("ͨµÀ%dµÄ²ÉÑùÖµ£º%d
",t+1,AD_Vaule_Average[t]);
adc[t]= AD_Vaule_Average[t];
temp[t]=(float)adc[t]*(3.3/4096); //µÃµ½ÊµÊýÀàÐͲÉÑùÖµ
adc2[t] =temp[t]; //µÃµ½ÕûÊý²¿·Ö
LCD_ShowxNum(130,80+t*20,adc2[t],1,RED,0);
temp[t]-=adc2[t]; //СÊý²¿·Ö
temp[t]*=1000;
LCD_ShowxNum(149,80+t*20,temp[t],3,RED,0);
}
printf("
");
delay_ms(200);[/mw_shl_code]
我说的是非DMA情况,针对你在十八楼贴的代码。
原子哥ADC例程是单通道,使用了一个Get_Adc(u8 ch) 函数
当改为多通道时 不知道如何读取
一周热门 更多>