ADC配置
void ADC_Configuration(void)
{
GPIOA->CRL&=0XFFFFF0Ff; //PA2êäèë
RCC->APB2ENR|=1<<2|1<<9; //¿aÆô
Aê±Öó ADCê±Öó
RCC->APB2RSTR|=1<<9; //¸′λADC1
RCC->APB2RSTR&=~(1<<9); // ¸′λíê3é ½«¸′λ1رÕ
RCC->CFGR|=2<<14; // éèÖÃÎa4·ÖÆμ¸øADC 12M
ADC1->CR1|=1<<8; //¿aÆôé¨ÃèÄ£ê½
ADC1->CR1|=1<<5; //ÔêDíÖD¶Ï
ADC1->CR2|=1<<0; //¿aÆôad
ADC1->CR2|=0<<1; //μ¥′Î×a»»
ADC1->CR2|=1<<2; //adD£×¼
while(ADC1->CR2&1<<2);//
ADC1->CR2|=1<<3; //
while(ADC1->CR2&1<<3);//
ADC1->CR2|=1<<8; //ê1ÄüDMA
ADC1->CR2|=3<<17; //
ADC1->CR2|=1<<20; //
ADC1->SMPR2|=0<<6; //
ADC1->SQR1|=0<<20; //
ADC1->SQR3&=0xFFFFFFE0; //1æÔòDòáD1 í¨μàch
ADC1->SQR3|=2;
MY_NVIC_Init(1,3,ADC1_2_IRQn,2);//ÇàÕ¼1£¬×óóÅÏ輶3£¬×é2
}
void ADC_IRQHandler(void)
{
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
FFT_IN[ADC_Count]= ADC_ConvertedValue;
if(ADC_Count<=255)ADC_Count++;
else
{
TIM2->CR1&=~(1<<0); //1رն¨ê±Æ÷2
ADC_Count=0;
adc_over=1;
}
}
定时器配置
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 ,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 ,ENABLE);
RCC->APB1ENR|=1<<0;
TIM2->CCMR1|=7<<12;
TIM2->CCMR1|=1<<11;
TIM2->ARR=1900;
TIM2->
SC=0;
TIM2->CCR2=0x23;
TIM2->CR1=0x8000;
TIM2->CCER|=1<<4;
TIM2->CR1|=0x01;
TIM_TimeBaseStructure.TIM_Period = 800; //¼ÆêyÖμ
TIM_TimeBaseStructure.TIM_Prescaler = 72-1; //Ô¤·ÖÆμ,′ËÖμ+1Îa·ÖÆμμÄ3yêy ¼ÆêyËù¶è1000K
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòéϼÆêy
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/*ê1ÄüԤװÔØ*/
TIM_ARRPreloadConfig(TIM3, ENABLE);
/*Ô¤ÏèÇå3yËùóDÖD¶Ïλ*/
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
/* òç3ö¶¼ÅäÖÃÖD¶Ï*/
TIM_ITConfig( TIM3,TIM_IT_Update, ENABLE);
/* ÔêDíTIM3¿aê¼¼Æêy */
TIM_Cmd(TIM3, ENABLE);
MY_NVIC_Init(1,3,TIM2_IRQn,2);//ÇàÕ¼0£¬×óóÅÏ輶3£¬×é2
MY_NVIC_Init(1,3,TIM3_IRQn,2);//ÇàÕ¼3£¬×óóÅÏ輶3£¬×é2
}
DMA配置
void ADC_DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* Enable DMA1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
//(2) 3õê¼»ˉ DMA oí ADC Ä£¿éóëó|óÃ3ìDò
/* DMA channel1 configuration ¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a¡a-*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; // íaéèμØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; // Äú′æμØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // DMA ′«êä·½Ïòμ¥Ïò
DMA_InitStructure.DMA_BufferSize = 1; // éèÖÃDMAÔú′«êäê±»o3åÇøμÄ3¤¶è word
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //éèÖÃDMAíaéèμYÔöÄ£ê½
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; // éèÖÃDMAÄú′æμYÔöÄ£ê½
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; // íaéèêy¾Y×Ö3¤
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //Äú′æêy¾Y×Ö3¤
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; // éèÖÃ′«êäÄ£ê½á¬Dø2»¶ÏμÄÑ-»·Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; // éèÖÃDMAμÄóÅÏ輶±e
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // éèÖÃDMAμÄ2¸ömemoryÖDμıäá¿»¥Ïà·ÃÎê
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
}
帮忙看下什么原因 谢谢 开了ADC中断程序就卡了 不开ADC中断 ADC采集的值是正确的 程序用库函数与寄存器混合的
一周热门 更多>