完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
STVD 4.3.10
宇宙V4.3.7 eBay el cheapo STM8S003F3P6(蓝色与B5上的LED) 大家好。我怀疑基本的中断编码有点问题。我的LED以可变速率闪烁,具有可变延迟,因此所有端口设置都可以,但是当我尝试使用具有中断的tiM时,似乎我无法更改更新中断标志。在调试器中输入中断服务程序,我可以单步执行它并切换LED但是一旦完成它就会直接返回到Int程序的开始。在监视窗口中,无论我使用什么代码,UIF标志都不会改变,但我可以手动更改它。在这种情况下,程序似乎在中断例程结束时挂起。这是代码 #define TIM2_CR1_ARPE((uint8_t)0x80)/ *!&lt;自动重新加载预加载启用掩码。 * / #define TIM2_CR1_OPM((uint8_t)0x08)/ *!&lt;一个脉冲模式掩码。 * / #define TIM2_CR1_URS((uint8_t)0x04)/ *!&lt;更新请求源掩码。 * / #define TIM2_CR1_UDIS((uint8_t)0x02)/ *!&lt;更新DIsable面具。 * / #define TIM2_CR1_CEN((uint8_t)0x01)/ *!&lt;计数器启用掩码。 * / #define TIM2_IER_UIE((uint8_t)0x01)/ *!&lt;更新中断启用掩码。 * / #define TIM2_SR1_UIF((uint8_t)0x01)/ *!&lt;更新中断标志掩码。 * / / * SR2 * / void main(void) { DISABLE_INTERRUPTS(); SetupOutputPortB(); InitialiseTimer2(); SetupTimer2(); // enable_interrupts(); 中main_loop(); 返回; } void main_loop(void) { 而(1) { //我们的LED在B5端口 //打开和关闭输出然后延迟延迟(40000); GPIOB-> ODR ^ = BIT5; // 1&lt;&lt; 5; // PB.5 XOR PIN5切换//延迟闪烁正常工作 } } void InitialiseTimer2() { TIM2-> CR1 = 0; //关闭所有与TIM2相关的内容。 TIM2-> IER = 0; TIM2-> SR1 = 0; TIM2-> SR2 = 0; TIM2-> CCER1 = 0; TIM2-> CCER2 = 0; TIM2-> CCER1 = 0; TIM2-> CCER2 = 0; TIM2-> CCMR1 = 0; TIM2-> CCMR2 = 0; TIM2-> CCMR3 = 0; TIM2-> CNTRH = 0; TIM2-> CNTRL = 0; TIM2-> PSCR = 0; TIM2-> ARRH = 0; TIM2-> ARRL = 0; TIM2-> CCR1H = 0; TIM2-> CCR1L = 0; TIM2-> CCR2H = 0; TIM2-> CCR2L = 0; TIM2-> CCR3H = 0; TIM2-> CCR3L = 0; } void SetupTimer2() { TIM2_PSCR = 0x000f; // 2 ^ PSC [3:0] Prescaler.TIM2-&gt; ARRH = 0xef; // c3 195高字节50,000。 TIM2-> ARRL = 0xfe; // 55 85低字节50,000。 TIM2-> CR1 | = TIM2_CR1_ARPE; // 0x80的;启用自动重新加载预加载 TIM2-&gt; IER | = TIM2_IER_UIE; // 0×01; TIM2更新中断已启用 TIM2-> CR1 | = STM8_TIMx_CR1_CEN; // 0×01;打开计时器 } @far @interrupt void TIM2_UPD_OVF_IRQHandler(void); // #define IRQ13 TIM2_UPD_OVF_IRQHandler @ interrupt void TIM2_UPD_OVF_IRQHandler(void){ //中断例程被称为没问题。 GPIOB-> ODR ^ = BIT5; // PB.5 XOR PIN5 / *甚至TIM2_SR1 = 0;不起作用* / TIM2_SR1 ^ = TIM2_SR1_UIF; //; 0×01 / *重置中断否则会立即再次触发。 它无论如何都要做* / // disable_interrupts(); 所以有人能弄清楚我在这里缺少什么吗? 以上来自于谷歌翻译 以下为原文 STVD 4.3.10 Cosmic V4.3.7 eBay el cheapo STM8S003F3P6 (The blue one with the LED on B5) Hello all. I am having a bit of a problem with I suspect basic interrupt coding. I have the LED blinking at a variable rate with a variable delay so all the port setups are OK but when I try to use TIMs with an interrupt it appears that I cannot change the Update Interrupt flag. In the debugger the interrupt service routine is entered, I can single step through it and toggle the LED but as soon as it is finished it goes straight back to the start of the Int routine. In the watch window the UIF flag does not get changed no matter what code I use but I can change it manually. In which case the program just seems to hang at the end of the interrupt routine. Here is the code #define TIM2_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */ #define TIM2_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */ #define TIM2_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */ #define TIM2_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */ #define TIM2_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */#define TIM2_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */ #define TIM2_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */ /*SR2*/void main( void ) { disable_interrupts(); SetupOutputPortB(); InitialiseTimer2(); SetupTimer2(); //enable_interrupts(); main_loop(); return; }void main_loop(void) { while(1) { // Our LED is on Port B5 //Turn on and off the output and then delay delay(40000); GPIOB->ODR ^= BIT5; //1<<5;// PB.5 XOR PIN5 Toggle// Delay blink works fine } } void InitialiseTimer2() { TIM2->CR1 = 0; // Turn everything TIM2 related off. TIM2->IER = 0; TIM2->SR1 = 0; TIM2->SR2 = 0; TIM2->CCER1 = 0; TIM2->CCER2 = 0; TIM2->CCER1 = 0; TIM2->CCER2 = 0; TIM2->CCMR1 = 0; TIM2->CCMR2 = 0; TIM2->CCMR3 = 0; TIM2->CNTRH = 0; TIM2->CNTRL = 0; TIM2->PSCR = 0; TIM2->ARRH = 0; TIM2->ARRL = 0; TIM2->CCR1H = 0; TIM2->CCR1L = 0; TIM2->CCR2H = 0; TIM2->CCR2L = 0; TIM2->CCR3H = 0; TIM2->CCR3L = 0; }void SetupTimer2() { TIM2_PSCR = 0x000f; // 2^PSC[3:0] Prescaler.TIM2->ARRH = 0xef; // c3 195 High byte of 50,000. TIM2->ARRL = 0xfe; // 55 85 Low byte of 50,000. TIM2->CR1 |= TIM2_CR1_ARPE; //0x80; Auto reload preload enabled TIM2->IER |= TIM2_IER_UIE; //0x01; TIM2 Update Interrupt enabled TIM2->CR1 |= STM8_TIMx_CR1_CEN; //0x01; Turn ON timer }@far @interrupt void TIM2_UPD_OVF_IRQHandler(void); //#define IRQ13 TIM2_UPD_OVF_IRQHandler@interrupt void TIM2_UPD_OVF_IRQHandler(void){ // Interrupt routine is called no problem. GPIOB->ODR ^= BIT5; // PB.5 XOR PIN5 /* Even TIM2_SR1 = 0; Does not work */ TIM2_SR1 ^= TIM2_SR1_UIF; //; 0x01 /*Reset the interrupt otherwise it will fire again straight away. Which it does anyway */ // disable_interrupts(); }So can anybody figure out what I am missing here? |
|
相关推荐
6个回答
|
|
这是第一个罪犯
TIM2_SR1 ^ = TIM2_SR1_UIF; //; 0×01 应该是哪个 TIM2-> SR1&amp; = 0xfe;要么 TIM2-> SR1&amp; =!TIM2_SR1_UIF; 我也找到了 TIM2_PSCR = 0x000f; // 2 ^ PSC [3:0]预分频器。 那应该是 TIM2-> PSCR = 0x000f; // 2 ^ PSC [3:0]预分频器。 就像我改变了所有其他人一样。从所有不同编译器的示例中剪切和粘贴时出现问题。虽然做了一个好的bug追捕 以上来自于谷歌翻译 以下为原文 Here is the first offender TIM2_SR1 ^= TIM2_SR1_UIF; //; 0x01 Which should be TIM2->SR1 &= 0xfe; or TIM2->SR1 &= !TIM2_SR1_UIF; I also found TIM2_PSCR = 0x000f; // 2^PSC[3:0] Prescaler. That should be TIM2->PSCR = 0x000f; // 2^PSC[3:0] Prescaler. Like I changed all the others to. Bit of a problem when cutting and pasting from examples for all different compilers. Makes for a good bug hunt though |
|
|
|
你确定RMW表格是否正确,它不只是使用Write-Zero模型吗?
TIM2-> SR1 =!TIM2_SR1_UIF; &amp; =形式具有清除读和写阶段之间发生的中断的副作用。 以上来自于谷歌翻译 以下为原文 Are you sure the RMW form is correct, doesn't it just use a Write-Zero model? TIM2->SR1 = !TIM2_SR1_UIF; The &= form has a side-effect of clearing interrupts that occur between the Read and Write phases. |
|
|
|
谢谢克莱夫。在调试器中查看此内容,
temp =!TIM2_SR1_UIF; TIM2-> SR1 = temp; !0x01变为0x00。因此 TIM2-> SR1 =!TIM2_SR1_UIF; 不仅重置了UIF,还破坏了SR1中的所有其他位。出于可移植性和代码安全的原因,我宁愿只改变我追求的位。这导致我这也解决了&amp; =相位延迟问题 _asm('BRES TIM2_SR1,BIT0'); 这当然在编译器中不起作用。 '符号没有定义'和迄今为止的宇宙手册说得足够接近'它无法完成'。 “ 请注意,现有C对象无法直接连接。 “所以它对便携性或可读性不好,但我暂时还没有这个。 _asm('BRES 0x5304,♯0'); //清除TIM2 UIF 不完美,但它闪烁的LED。 以上来自于谷歌翻译 以下为原文 Thanks Clive. Looking at this in the debugger, temp = !TIM2_SR1_UIF; TIM2->SR1 = temp; !0x01 becomes 0x00. Therefore TIM2->SR1 = !TIM2_SR1_UIF; Not only resets the UIF but clobbers all the other bits in SR1. I would prefer to change only the bit I am after for portability and code safety reasons. That leads me to this to fix the &= phase delay problem as well _asm('BRES TIM2_SR1, BIT0'); Which of course does not work in the compiler. 'symbol not defined' and the Cosmic manual so far says close enough to 'it cannot be done'. ' Note that there is no direct connection possible with existing C objects. 'So it is not good for portability or readability but I am left with this for the moment. _asm('BRES 0x5304, ♯ 0'); // Clear TIM2 UIF Not perfect but it is flashing the LED. |
|
|
|
对不起,代字号操作很可能是我们想要的,不应该切割粘贴
TIM2-> SR1 = ~TIM2_SR1_UIF; 其中~0x01是0xFE 以上来自于谷歌翻译 以下为原文 Sorry, tilde operation is likely the one we want, shouldn't have cut-n-pasted TIM2->SR1 = ~TIM2_SR1_UIF; Where ~0x01 is 0xFE |
|
|
|
,
, 当然是波浪形。为什么我没想到这一点。然而,它仍然对所有其他位进行任意更改,因此并不理想。所以看着这个。 _asm('BRES 0x3c55,♯0'),,, ,,, scratch [0] ^ = 0x01 ,, ,,, scratch [1] = ~skle [2],引导编译器生成这个 ,53 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,56,0000 72113c55 ,,,,, BRES 0x3c55,♯0, ,58 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,60,0004 b601 ,,,,,,,,,,,, ld ,,, a,_scratch + 1, ,61,0006 a801 ,,,,,,,,,,,, xor ,,, a,♯1, ,62,0008 b701 ,,,,,,,,,,,, ld ,,,, scratch + 1,a,63 ,,,,,,,,,,,,,,,,,,,,, 14 ,,,刮[1] =〜刮[2] ,, ,65,000a be04 ,,,,,,,,,,, ldw ,,, x,_scratch + 4, ,66,000c 53 ,,,,,,,,,,,,,,, cplw ,,, x, ,67,000d bf02 ,,,,,,,,,,,, ldw ,,,, scratch + 2,x手册将BRES指令描述为读取,修改,写入操作,因此这三者在这方面大致相同。唯一真正的区别是所需的额外程序空间和指令长度以及所需的时钟周期。我没有在指令集上找到任何提供这种细节的文档。 BRES更短,只有一条指令,我确实尝试编写一个子来创建文本字符串但是在Cosmic中似乎没有sprintf然后我试了这个 char命令[64] ='BRES 0x3c55,♯0',,, , ,,, _asm(命令),但它给了我 ♯错误cpstm8 main.c:16(0)bad _asm()参数typeEven with all&amp; ,, [],[0] ...我想到的变种 在这个阶段,我认为稍微不那么美观_asm('BRES 0x3c55,♯0'),硬编码是赢家。 以上来自于谷歌翻译 以下为原文 , , Of course the tilde. Why didn't I think of that. However it still does an arbitrary change to all the other bits as well so not ideal. So looking at this. _asm('BRES 0x3c55, ♯ 0'), , , , ,scratch[0] ^= 0x01, , , , ,scratch[1] = ~scratch[2],Leading the compiler to generate this ,53 , , , , , , , , , , , , , , , , , , , , , 12 , , ,_asm('BRES 0x3c55, ♯ 0'), , , 56 , 0000 72113c55 , , , , , BRES 0x3c55, ♯ 0 , , 58 , , , , , , , , , , , , , , , , , , , , , 13 , , ,scratch[0] ^= 0x01, , , 60 , 0004 b601 , , , , , , , , , , , ,ld , , ,a,_scratch+1 , , 61 , 0006 a801 , , , , , , , , , , , ,xor , , ,a, ♯ 1 , , 62 , 0008 b701 , , , , , , , , , , , ,ld , , ,_scratch+1,a , 63 , , , , , , , , , , , , , , , , , , , , , 14 , , ,scratch[1] = ~scratch[2], , , 65 , 000a be04 , , , , , , , , , , , ldw , , ,x,_scratch+4 , , 66 , 000c 53 , , , , , , , , , , , , , , cplw , , ,x , , 67 , 000d bf02 , , , , , , , , , , , ,ldw , , ,_scratch+2,xThe manual describes the BRES instruction as a Read,Modify,Write operation anyway so all three are much the same in that regard. The only real difference is the extra program space required and in the instruction length and therefore the clock cycles required. I have not found any documentation on the instruction set that gives that sort of detail though. BRES is shorter and only one instruction and I did try to write a sub to create the text string from but there appears to be no sprintf in Cosmic and then I tried this char command[64] = 'BRES 0x3c55, ♯ 0', , , , , ,_asm(command),But it gives me ♯ error cpstm8 main.c:16(0) bad _asm() argument typeEven with all &,,[],[0] ... variants I could think of At this stage I think the slightly less aesthetic _asm('BRES 0x3c55, ♯ 0'), hardcoding is the winner. |
|
|
|
,
, 呸!我发布后为什么总要想到这些东西?怎么样。 ♯定义TIM2_UIF_RESET'BRES 0x3c55,♯0', , ,,, _asm(TIM2_UIF_RESET),编译为 ,53 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,5600 0033 72113c55 ,,,,, BRES 0x3c55,♯0我觉得我没有破坏任何代码美化规则吗?它当然是代码大小和执行速度最有效的方法,并且不会破坏任何其他位。它特别改变了所需的一个。可移植性仍然是一个问题,但它可以与所有其他设备特定的定义一起放在标题中,这样也可以解决。 以上来自于谷歌翻译 以下为原文 , , Pah! Why do I always think of these things after I posted? How about. ♯ define TIM2_UIF_RESET 'BRES 0x3c55, ♯ 0' , , , , ,_asm(TIM2_UIF_RESET),Which compiles to , 53 , , , , , , , , , , , , , , , , , , , , , 12 , , , _asm(TIM2_UIF_RESET), , , 56 , 0000 72113c55 , , , , , BRES 0x3c55, ♯ 0I dont think I have broken any code beautification rules there have I? It is certainly the most efficient method in code size and execution speed and does not clobber any other bits. It specifically alters only the one required. Portability is still an issue but it could go in the headers along with all the other device specific defines so that is solved too. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2612 浏览 1 评论
3201 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1775 浏览 1 评论
3600 浏览 6 评论
5980 浏览 21 评论
931浏览 4评论
1308浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
576浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1295浏览 3评论
1350浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 05:24 , Processed in 1.196111 second(s), Total 87, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号