完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近在使用STM32F0做一个AVR控制简单逻辑,比较奇怪的是,只开启前8个通道一切正常,大于8个以上会进入死EOC死等待,读取AD使用同一个函数,具体如下:
void STM32_RCC_Init(void) { RCC->CR |= RCC_CR_HSION; while((RCC->CR&RCC_CR_HSIRDY)== 0); // RCC->CFGR |= RCC_CFGR_SWS_PLL; // RCC->CFGR |= RCC_CFGR_PLLXTPRE_HSE_PREDIV_DIV2; RCC->CFGR |= RCC_CFGR_PLLSRC_HSI_DIV2; RCC->CFGR |= RCC_CFGR_SW_PLL; RCC->CFGR |= RCC_CFGR_PLLMUL12; RCC->CR |= RCC_CR_PLLON; while((RCC->CR&RCC_CR_PLLRDY) == 0); // RCC->APB2RSTR |= RCC_APB2RSTR_tiM16RST; // RCC->APB2RSTR |= RCC_APB2RSTR_TIM1RST; // RCC->APB2RSTR |= RCC_APB2RSTR_ADCRST; RCC->AHBENR = RCC->AHBENR|RCC_AHBENR_GPIOAEN|RCC_AHBENR_GPIOBEN |RCC_AHBENR_GPIOCEN|RCC_AHBENR_GPIODEN; RCC->APB2ENR = RCC->APB2ENR|RCC_APB2ENR_SYSCFGCOMPEN |RCC_APB2ENR_ADCEN|RCC_APB2ENR_TIM16EN|RCC_APB2ENR_TIM1EN; RCC->CR2 |= RCC_CR2_HSI14ON; while(RCC_CR2_HSI14RDY == 0); } void STM32_GPIO_Init(void) { GPIOA->MODER = 0x6955ffff; // GPIOA->MODER = 0x2800ffff; GPIOB->MODER = 0x55565557; GPIOB->AFR[1] = 0x02; GPIOC->MODER = 0x00115fff; GPIOD->MODER = 0x00000010; } void STM32_ADC_Init(void) { ADC1->SMPR |= ADC_SMPR_SMP_2|ADC_SMPR_SMP_0; ADC1->CR |= ADC_CR_ADCAL; while(((ADC1->CR)&ADC_CR_ADCAL) != 0); ADC1->CFGR1 |= ADC_CFGR1_OVRMOD; ADC1->CR |= ADC_CR_ADEN; while(((ADC1->ISR)&ADC_ISR_ADRDY) == 0); } //读取AD值函数 unsigned short ADConvertValues(unsigned char ADChanel) { unsigned char ADC_DelayCNT = 0; while(((ADC1->ISR)&ADC_ISR_ADRDY) == 0); ADC1->CHSELR = (1< while (!((ADC1->ISR) & ADC_ISR_EOC)); /* { ADC_DelayCNT++; if(ADC_DelayCNT>250) { return ADC1->DR; } } */ return ADC1->DR; } //前面8通道读取在定时器TIM1里面做的,一切正常。 void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { static unsigned short PowButtonCheckcnt; static unsigned short PageDownCheckcnt; static unsigned short LcdCnt; unsigned short DataTep; unsigned short DataTepA; unsigned short DataTepB; unsigned short DataTepC; unsigned long DataComp; unsigned char ADCCH; TIM1->SR = 0x00; McLedBoostOn; for(ADCCH=0;ADCCH<9;ADCCH++) { DataTep = ADConvertValues(ADCCH); if(DataTep >= AdOffSetValue) { DataTep = DataTep - AdOffSetValue; } else { DataTep = AdOffSetValue - DataTep; } DataComp = DataTep; DataComp = DataComp*DataTep; switch(ADCCH) { //InputVoltageRMS/ case 0: NewInPutAPhaseVoltageBuff = NewInPutAPhaseVoltageBuff+DataComp; break; case 1: NewInPutBPhaseVoltageBuff = NewInPutBPhaseVoltageBuff+DataComp; break; case 2: NewInPutCPhaseVoltageBuff = NewInPutCPhaseVoltageBuff+DataComp; break; //OutputVoltageRMS/ case 3: NewOutPutAPhaseVoltageBuff = NewOutPutAPhaseVoltageBuff+DataComp; DataTepA = DataTep; break; case 4: NewOutPutBPhaseVoltageBuff = NewOutPutBPhaseVoltageBuff+DataComp; DataTepB = DataTep; break; case 5: NewOutPutCPhaseVoltageBuff = NewOutPutCPhaseVoltageBuff+DataComp; DataTepC = DataTep; break; //OutputVoltageCurrent/ case 6: NewOutPutAPhaseCurrentBuff = NewOutPutAPhaseCurrentBuff+DataComp; DataComp = DataTepA; DataComp = DataComp*DataTep; NewOutPutAPhaseWatBuff = NewOutPutAPhaseWatBuff+DataComp; break; case 7: NewOutPutBPhaseCurrentBuff = NewOutPutBPhaseCurrentBuff+DataComp; DataComp = DataTepB; DataComp = DataComp*DataTep; NewOutPutBPhaseWatBuff = NewOutPutBPhaseWatBuff+DataComp; break; case 8: NewOutPutCPhaseCurrentBuff = NewOutPutCPhaseCurrentBuff+DataComp; DataComp = DataTepC; DataComp = DataComp*DataTep; NewOutPutCPhaseWatBuff = NewOutPutCPhaseWatBuff+DataComp; break; } } AD_CONV_CNT++; NTC_Check_Funcion(); if(AD_CONV_CNT == 0x36) { GPIOA->BRR = (~(unsigned short)(AVRControl_REG<<8))&0xff00; } if(AD_CONV_CNT == 0x4a) { if(New_mode != OutRang_mode) { GPIOA->BSRR = (unsigned short)(AVRControl_REG<<8)&0xff00; } } } //后面8通道用于NTC采样,只要开启一组就有问题,无论该函数放在中断也好,主函数也好,采取单通道扫描也会出现一样问题。 void NTC_Check_Funcion(void) { switch(NTC_AD_CNT) { case 9: NTC_RSCR_Ad_Buff = NTC_RSCR_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 10: NTC_SSCR_Ad_Buff = NTC_SSCR_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 11: NTC_TSCR_Ad_Buff = NTC_TSCR_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 12: NTC_RTX_Ad_Buff = NTC_RTX_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 13: NTC_STX_Ad_Buff = NTC_STX_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 14: NTC_TTX_Ad_Buff = NTC_TTX_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; case 15: NTC_ENV_Ad_Buff = NTC_ENV_Ad_Buff+ADConvertValues(NTC_AD_CNT); break; } NTC_AD_CNT++; if(NTC_AD_CNT == 10) { NTC_AD_CNT = 9; NTC_CheckCnt ++; } if(NTC_CheckCnt == 16) { NTC_CheckCnt = 0; NTC_RSCR_Ad_Buff = NTC_RSCR_Ad_Buff>>4; NTC_SSCR_Ad_Buff = NTC_SSCR_Ad_Buff>>4; NTC_TSCR_Ad_Buff = NTC_TSCR_Ad_Buff>>4; NTC_RTX_Ad_Buff = NTC_RTX_Ad_Buff>>4; NTC_STX_Ad_Buff = NTC_STX_Ad_Buff>>4; NTC_TTX_Ad_Buff = NTC_TTX_Ad_Buff>>4; NTC_ENV_Ad_Buff = NTC_ENV_Ad_Buff>>4; NTC_RSCR_Level = NTC_Level_Dect(NTC_RSCR_Ad_Buff); NTC_SSCR_Level = NTC_Level_Dect(NTC_SSCR_Ad_Buff); NTC_TSCR_Level = NTC_Level_Dect(NTC_TSCR_Ad_Buff); NTC_RTX_Level = NTC_Level_Dect(NTC_RTX_Ad_Buff); NTC_STX_Level = NTC_Level_Dect(NTC_STX_Ad_Buff); NTC_TTX_Level = NTC_Level_Dect(NTC_TTX_Ad_Buff); NTC_ENV_Level = NTC_Level_Dect(NTC_ENV_Ad_Buff); NTC_RSCR_Ad_Buff = 0; NTC_SSCR_Ad_Buff = 0; NTC_TSCR_Ad_Buff = 0; NTC_RTX_Ad_Buff = 0; NTC_STX_Ad_Buff = 0; NTC_TTX_Ad_Buff = 0; NTC_ENV_Ad_Buff = 0; if((NTC_RSCR_Level == 0xff)||(NTC_SSCR_Level == 0xff)||(NTC_TSCR_Level == 0xff) ||(NTC_RTX_Level == 0xff)||(NTC_STX_Level == 0xff)||(NTC_TTX_Level == 0xff) ||(NTC_ENV_Level == 0xff)) { STAT_FLAGE.TepError = 1; } } } |
|
相关推荐
16个回答
|
|
|
|
没人用寄存器版本操作吗,个人觉得寄存器执行效率还是会高一点
|
|
|
|
顶一下
|
|
|
|
会不会是堆栈溢出了吧。
|
|
|
|
不明觉厉
|
|
|
|
学习学习再学习
|
|
|
|
楼主,建议下,把你贴出的代码 放到一个文件中,添加附件
|
|
|
|
|
|
|
|
mark等待结果
|
|
|
|
不会寄存器的,飘过。。
|
|
|
|
分析寄存器太麻烦了,
|
|
|
|
用寄存器,没注释,得去找手册一个个对着分析,可移植性太差。
|
|
|
|
顶一下,楼主威武,强烈支持……
|
|
|
|
switch语句没有default是很危险的,建议加上
|
|
|
|
谢谢分享
|
|
|
|
8个ADC 通道呢,么,这个应该是你的配置的问题了
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2005 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1858 浏览 3 评论
4442 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2007 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2513 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 23:56 , Processed in 1.066614 second(s), Total 104, Slave 87 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号