为什么我DMA_Cmd使能,自己定义的变量、数组的数据都会变?
__IO uint16_t AD_Value1,AD_Value2;
void AD_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //AD1ºÍAD2Ï໥¶ÀÁ¢
ADC_InitStructure.ADC_ScanConvMode =ENABLE; //Ä£Êýת»»¹¤×÷ÔÚɨÃèģʽ
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //Ä£Êýת»»Ä£Ê½Á¬ÐøɨÃèģʽ
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //Íⲿ´¥·¢×ª»»¹Ø±Õ
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADCÊý¾ÝÓÒ¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = Pass_count; //˳Ðò½øÐÐADCͨµÀµÄÊýÄ¿
ADC_Init(ADC1, &ADC_InitStructure);
//ÉèÖÃÖ¸¶¨µÄAD¹æÔò×éͨµÀ¡¢×ª»¯Ë³Ðò¡¢²ÉÑùʱ¼ä
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_239Cycles5 );
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_239Cycles5 );
//¿ªÆôADCµÄDMAÖ§³Ö »¹ÐèÒªÅäÖÃDMAͨµÀ
ADC_DMACmd(ADC1, ENABLE);
//ʹÄÜADC
ADC_Cmd(ADC1, ENABLE);
//¸´Î»ADCµÄУ׼¼Ä´æÆ÷
ADC_ResetCalibration(ADC1);
//ÉèÖø´Î»ADCµÄУ׼¼Ä´æÆ÷µÄ״̬ΪµÈ´ý
while(ADC_GetResetCalibrationStatus(ADC1));
//¿ªÊ¼Ö¸¶¨ADCµÄУ׼״̬
ADC_StartCalibration(ADC1);
//»ñÈ¡Ö¸¶¨ADCУ׼³ÌÐòµÄ״̬ΪµÈ´ý
while(ADC_GetCalibrationStatus(ADC1));
}
void DMA_AD_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR; //DMAÍâÉèADC»ùµØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&AD_Value1; //DMAÄÚ´æ»ùµØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //ÄÚ´æ×÷ΪÊý¾Ý´«ÊäµÄÄ¿µÄµØ
DMA_InitStructure.DMA_BufferSize = Get_Freq*Pass_count; //DMA»º´æ´óС
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèµØÖ·¼Ä´æÆ÷²»±ä
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //ÄÚ´æ¼Ä´æÆ÷µØÖ·µÝÔö
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //Êý¾Ý¿í¶È16?
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //Êý¾Ý¿í¶È16?
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //¹¤×÷Ñ»·»º´æģʽ
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMAͨµÀÓµÓÐ×î¸ßÓÅÏȼ¶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMAûÓÐÉ豸ÄÚ´æµ½ÄÚ´æ¼äµÄ´«Êä
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
} 这个是我AD初始化和DMA初始化的代码 。
|