完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
亲爱的大家
我试图在宇宙编译器中读取stm8中的ADC1通道,但我还是不能。只要主程序开始配置ADC1初始化没有任何反应。我不知道中断的问题是什么。构建器中没有错误。 hex文件出来了。 void ADC_CONFIG(void) { ADC1_DeInit(); ADC1_Init(ADC1_CONVERSIONMODE_CONtiNUOUS,ADC1_CHANNEL_9,ADC1_PRESSEL_FCPU_D2,ADC1_EXTTRIG_GPIO,DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL9,DISABLE); ADC1_Cmd(ENABLE); ADC1_ITConfig(ADC1_IT_EOC,ENABLE); ADC1_StartConversion(); enableInterrupts(); } 这是ADC1的配置代码。但不幸的是我看不到任何中断功能的结果。该计划已在此停止, @interrupt void handleADCInt(void) { GPIO_WriteHigh(GPIOD,GPIO_PIN_0); if(ADC1_GetFlagStatus(ADC1_FLAG_EOC)== SET) { PRSC = ADC1_GetConversionValue(); } ADC1_ClearFlag(ADC1_FLAG_EOC); } 我在矢量文件中定义了中断函数。 非常感谢您的帮助 以上来自于谷歌翻译 以下为原文 Dear all I tried to read ADC1 channels in stm8 in cosmic compiler, but still I could not. as far as the main program start to config the ADC1 initialization nothing happen. I do not know what the problem is with interrupts. there is no error in builder. hex files came out. void ADC_CONFIG(void) { ADC1_DeInit(); ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_9,ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_GPIO, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL9,DISABLE); ADC1_Cmd(ENABLE); ADC1_ITConfig(ADC1_IT_EOC, ENABLE); ADC1_StartConversion(); enableInterrupts(); } here is the configuration codes for ADC1. but unfortunately I can not see any result in interrupt function. the program has stopped here, @interrupt void handleADCInt(void) { GPIO_WriteHigh(GPIOD, GPIO_PIN_0); if(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == SET) { prsc=ADC1_GetConversionValue(); } ADC1_ClearFlag(ADC1_FLAG_EOC); } I have defined the interrupt function in vector file. many thanks for your help |
|
相关推荐
1个回答
|
|
嗨,
在中断处理程序中,当ADC启用以产生多种中断时,您应首先调用/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html&sharpga950279308ea4bca1e2e8e213376f31b9 (/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html&sharpgae9f96f201b80ec24da0d51dbdb1660ee ITPendingBit)找到当前的ADC中断源并分别处理每个。如果EOC是唯一的来源,则无需执行此调用。您可能认为它是EOC。 如果中断源是EOC,则无需执行此操作 if(ADC1_GetFlagStatus(ADC1_FLAG_EOC)== SET) 由于ADC中断,这个“if”始终为真。 只需读取ADC值即可。 然后你忘了重置ADC1_IT_EOC标志,ADC EOC中断挂起标志。 因此,在一次ADC中断后,标志保持置1。对于CPU,中断似乎没有处理,因此它将阻止进一步的ADC EOC中断。 读取值后,您处理了中断,只需要告诉CPU。 使用无效 /public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html&sharpga2450f7bbab4cff6a76605b5278741715 (/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html&sharpgae9f96f201b80ec24da0d51dbdb1660ee ITPendingBit) 使用参数ADC1_IT_EOC复位ADC EOC中断挂起标志。 注意 读取ADC值有可能会重置ADC1_IT_EOC 自动标志(怀疑)。我没有找那个。 HTH, 约翰 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 Hi, In the interrupt handler, when the ADC is enabled to generate several kinds of interrupts, you should first call /public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html&sharpga950279308ea4bca1e2e8e213376f31b9 (/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html&sharpgae9f96f201b80ec24da0d51dbdb1660ee ITPendingBit) to find the current ADC interrupt source and deal with each separately. If EOC is the only source, you do not need to do this call. You may assume it is EOC. If the interrupt source is EOC, there is no need to do if (ADC1_GetFlagStatus(ADC1_FLAG_EOC) == SET) Because of the ADC interrupt this 'if' is always true. Just read the ADC value and do stuff. Then you forgot to Reset the ADC1_IT_EOC flag, the ADC EOC interrupt pending flag. So after one ADC interrupt, the flag remains set. To the CPU, the interrupt seems not handled, so it will block further ADC EOC interrupts. After you read the value, you handled the interrupt and just need to tell the CPU. Use void /public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html&sharpga2450f7bbab4cff6a76605b5278741715 ( /public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html&sharpgae9f96f201b80ec24da0d51dbdb1660ee ITPendingBit ) with parameter ADC1_IT_EOC to reset the ADC EOC interrupt pending flag. Note There is a possibility that reading the ADC value resets the ADC1_IT_EOC flag automaticaly (doubt it). I have not looked for that. HTH, John Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2742 浏览 1 评论
3244 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1813 浏览 1 评论
3653 浏览 6 评论
6044 浏览 21 评论
1342浏览 4评论
203浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
356浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
446浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
275浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 08:18 , Processed in 1.154630 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号