问题遇到的现象和发生背景
帮忙看下stm32h7寄存器操作 实现定时器触发adc中断采样的代码,不知道为啥进不去中断,不知道是否配置错误
问题相关代码,请勿粘贴截图
u16 adcbuffer[1000];
int i;
void Adc_Init(void)
{
//Ïȳõʼ»¯IO¿Ú
RCC->AHB1ENR|=1<<5; //ʹÄÜADC1/2ʱÖÓ
RCC->AHB4ENR|=1<<0; //ʹÄÜPORTAʱÖÓ
GPIO_Set(GPIOA,PIN6,GPIO_MODE_AIN,0,0,GPIO_PUPD_NONE);//PA6,Ä£ÄâÊäÈë,²»´øÉÏÏÂÀ
RCC->AHB1RSTR|=1<<5; //ADC1/2¸´Î»
RCC->AHB1RSTR&=~(1<<5); //¸´Î»½áÊø
RCC->D3CCIPR&=~(3<<16); //ADCSEL[1:0]ÇåÁã
RCC->D3CCIPR|=2<<16; //ADCSEL[1:0]=2,per_ck×÷ΪADCʱÖÓÔ´,ĬÈÏÑ¡Ôñhsi_ker_ck×÷Ϊper_ck,ƵÂÊ:64Mhz
ADC12_COMMON->CCR|=1<<18; //PRESC[3:0]=1,ÊäÈëʱÖÓ2·ÖƵ,¼´adc_ker_ck=per_ck/2=64/2=32Mhz(²»Äܳ¬¹ý36Mhz)
ADC1->CR=0; //CR¼Ä´æÆ÷ÇåÁã,DEEPPWDÇåÁã,´ÓÉî¶È˯Ãß»½ÐÑ.
ADC1->CR|=1<<28; //ADVREGEN=1,ʹÄÜADCÎÈѹÆ÷
delay_ms(10); //µÈ´ýÎÈѹÆ÷Æô¶¯Íê³É,Ô¼10us,ÕâÀïÑÓʱ´óÒ»µã,û¹Øϵ.
ADC1->CR|=1<<8; //BOOST=1,ADC¹¤×÷ÔÚboostģʽ(ADCƵÂÊ´óÓÚ20MµÄʱºò,±ØÐëÉèÖÃboostλ)
ADC1->CFGR&=~(1<<13); //CONT=0,µ¥´Îת»»Ä£Ê½
ADC1->CFGR|=1<<12; //OVRMOD=1,¸´Ð´Ä£Ê½(DR¼Ä´æÆ÷¿É±»¸´Ð´)
ADC1->CFGR|=2<<5; //EXTSEL[4:0]=2,TIM2 TAGOʼþ
ADC1->CFGR|=1<<10; //EXTEN[1:0]=0,ÉÏÉýÑØ´¥·¢
ADC1->CFGR&=~(7<<2); //RES[2:0]λÇåÁã
ADC1->CFGR|=0<<2; //RES[2:0]=0,16λ·Ö±æÂÊ(0,16λ;1,14λ;2,12λ;3,10λ;4,8λ.)
ADC1->CFGR2&=~((u32)15<<28);//LSHIFT[3:0]=0,²»×óÒÆ,Êý¾ÝÓÒ¶ÔÆë.
ADC1->CFGR2&=~((u32)0X3FF<<16);//OSR[9:0]=0,²»Ê¹Óùý²ÉÑù
ADC1->CR&=~((u32)1<<30); //ADCALDIF=0,У׼µ¥¶Ëת»»Í¨µÀ
ADC1->CR|=1<<16; //ADCALLIN=1,ÏßÐÔУ׼
ADC1->CR|=(u32)1<<31; //¿ªÆôУ׼
while(ADC1->CR&((u32)1<<31));//µÈ´ýУ׼Íê³É
ADC1->SQR1&=~(0XF<<0); //L[3:0]ÇåÁã
ADC1->SQR1|=0<<0; //L[3:0]=0,1¸öת»»ÔÚ¹æÔòÐòÁÐÖÐ Ò²¾ÍÊÇֻת»»¹æÔòÐòÁÐ1
//ÉèÖÃͨµÀ3µÄ²ÉÑùʱ¼ä
ADC1->SMPR1&=~(0<<(1*9)); //ͨµÀ3²ÉÑùʱ¼äÇå¿Õ
ADC1->SMPR1|=0<<(1*9); //ͨµÀ3 1.5¸öÖÜÆÚ
ADC1->IER|=1<<2;//ʹÄÜEOCÖжÏ
MY_NVIC_Init(1,3,ADC_IRQn,2);
ADC1->CR|=1<<0; //¿ªÆôADת»»Æ÷
ADC1->PCSEL|=1<<3; //ADCת»»Í¨µÀԤѡÔñ
//ÉèÖÃת»»ÐòÁÐ
ADC1->SQR1&=~(0X1F<<6*1); //¹æÔòÐòÁÐ1ͨµÀÇåÁã
ADC1->SQR1|=3<<6*1; //ÉèÖùæÔòÐòÁÐ1µÄת»»Í¨µÀΪ3
ADC1->CR|=1<<2; //Æô¶¯¹æÔòת»»Í¨µÀ
}
//ÉèÖö¨Ê±Æ÷´¥·¢ad²ÉÑù
void TIM2_Int_Init(void)
{
RCC->APB1LENR|=1<<1; //TIM2ʱÖÓʹÄÜ
//Èç¹û¿ªÆôTIM2ʱÖÓºó,Ö±½Ó¿ªÊ¼ÅäÖÃTIM2,Ôò»áÓÐÎÊÌâ
while((RCC->APB1LENR&(1<<1))==0){
} //µÈ´ýʱÖÓÉèÖÃOK
TIM2->ARR=10-1; //É趨¼ÆÊýÆ÷×Ô¶¯ÖØ×°Öµ
TIM2->PSC=10-1; //Ô¤·ÖƵÆ÷
TIM2->SMCR=0; //SMS[3:0]=0000,CK_INT×÷ΪʱÖÓÔ´
//TIM2->DIER|=1<<0; //ÔÊÐí¸üÐÂÖжÏ
TIM2->CR1&=(3<<5); //CMS[1:0]=00,±ßÑضÔÆëģʽ(1<<4); //DIR=0,ÏòÉϼÆÊýģʽ
TIM2->CR1&=
TIM2->CR2|=2<<4; //update
TIM2->CR1|=0x01; //ʹÄܶ¨Ê±Æ÷2
//MY_NVIC_Init(1,3,TIM2_IRQn,2); //ÇÀÕ¼1£¬×ÓÓÅÏȼ¶3£¬×é2
}
void ADC_IRQHandler(){
if(!(ADC1->ISR&1<<2)){
if(i==1000){
i=0;
}
adcbuffer[i]=ADC1->DR;
i++;
}
ADC1->ISR&=~(1<<2);
}
运行结果及报错内容
进不去中断