你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 9443|回复: 14

STM8L的外部中断死循环

[复制链接]

1

主题

3

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2014-7-7 16:01:45 | 显示全部楼层 |阅读模式
 我想起用外部中断0和外部中断6。经过我的设置,程序总是在外部中断6的服务程序里运行。PC6的输入电平一直是低电平。即使我将PC6相关的中断语句屏蔽掉。程序就在EXIT0中断服务程序里死循环。下面是我的设置:
I/O口设置:
void CC113L_SPI_GPIOInit(void)
{
  GPIO_Init(GPIOD, GPIO_Pin_0, GPIO_Mode_In_FL_IT);             //GDO0       外部中断0
  GPIO_Init(GPIOB, GPIO_Pin_5, GPIO_Mode_Out_PP_Low_Slow);        //SCK  
  GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_Out_PP_Low_Slow);        //MOSI 
  GPIO_Init(GPIOA, GPIO_Pin_2, GPIO_Mode_In_PU_No_IT);            //MISO 
  GPIO_Init(GPIOC, GPIO_Pin_4, GPIO_Mode_Out_PP_Low_Slow);        //CSN  
GPIO_Init(GPIOC, GPIO_Pin_5, GPIO_Mode_In_FL_No_IT);  
}


void USART_GpioInit(void)
{
        GPIO_Init(GPIOC, GPIO_Pin_6, GPIO_Mode_In_FL_IT);         //外部中断6
        GPIO_Init(GPIOC, GPIO_Pin_0, GPIO_Mode_Out_PP_High_Slow);     //PC0        
}
void EXIT_Init(void)
{
        EXTI_DeInit();
        EXTI_SetPinSensitivity(GPIO_Pin_0,EXTI_Trigger_Rising);
        EXTI_SetPinSensitivity(GPIO_Pin_6,EXTI_Trigger_Falling);
        ITC_SetSoftwarePriority(EXTI6_IRQn,ITC_PriorityLevel_3); 
        ITC_SetSoftwarePriority(EXTI0_IRQn,ITC_PriorityLevel_2); 
        EXTI_ClearITPendingBit(EXTI_IT_Pin6);
        EXTI_ClearITPendingBit(EXTI_IT_Pin0);
        enableInterrupts();
}


下面是Vector.c里的设置:
#include "stm8l15x_it.h"
typedef void @far (*interrupt_handler_t)(void);


struct interrupt_vector {
        unsigned char interrupt_instruction;
        interrupt_handler_t interrupt_handler;
};


@far @interrupt void NonHandledInterrupt (void)
{
        /* in order to detect unexpected events during development, 
           it is recommended to set a breakpoint on the following instruction
        */
        return;
}


extern void _stext();     /* startup routine */
extern void EXTI0_IRQHandler(void);
extern void EXTI6_IRQHandler(void);


struct interrupt_vector const _vectab[] = {
        {0x82, (interrupt_handler_t)_stext}, /* reset */
        {0x82, NonHandledInterrupt}, /* trap  */
        {0x82, NonHandledInterrupt}, /* irq0  */
        {0x82, NonHandledInterrupt}, /* irq1  */
        {0x82, NonHandledInterrupt}, /* irq2  */
        {0x82, NonHandledInterrupt}, /* irq3  */
        {0x82, NonHandledInterrupt}, /* irq4  */
        {0x82, NonHandledInterrupt}, /* irq5  */
        {0x82, NonHandledInterrupt}, /* irq6  */
        {0x82, NonHandledInterrupt}, /* irq7  */
        {0x82, EXTI0_IRQHandler}, /* irq8  */
        {0x82, NonHandledInterrupt}, /* irq9  */
        {0x82, NonHandledInterrupt}, /* irq10 */
        {0x82, NonHandledInterrupt}, /* irq11 */
        {0x82, NonHandledInterrupt}, /* irq12 */
        {0x82, NonHandledInterrupt}, /* irq13 */
        {0x82, EXTI6_IRQHandler}, /* irq14 */
        {0x82, NonHandledInterrupt}, /* irq15 */
        {0x82, NonHandledInterrupt}, /* irq16 */
        {0x82, NonHandledInterrupt}, /* irq17 */
        {0x82, NonHandledInterrupt}, /* irq18 */
        {0x82, NonHandledInterrupt}, /* irq19 */
        {0x82, NonHandledInterrupt}, /* irq20 */
        {0x82, NonHandledInterrupt}, /* irq21 */
        {0x82, NonHandledInterrupt}, /* irq22 */
        {0x82, NonHandledInterrupt}, /* irq23 */
        {0x82, NonHandledInterrupt}, /* irq24 */
        {0x82, NonHandledInterrupt}, /* irq25 */
        {0x82, NonHandledInterrupt}, /* irq26 */
        {0x82, NonHandledInterrupt}, /* irq27 */
        {0x82, NonHandledInterrupt}, /* irq28 */
        {0x82, NonHandledInterrupt}, /* irq29 */
};


外部中断6的服务程序(在it.c里面):
@far @interrupt void EXTI6_IRQHandler(void) 
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
        EXTI_ClearITPendingBit(EXTI_IT_Pin6);   
        time_ok = 1;
        sleep_ok = 1;        
                
}


外部中断0 的服务程序:
@far @interrupt void EXTI0_IRQHandler(void) 
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
        INT8U length = 0x05;
        EXTI_ClearITPendingBit(EXTI_IT_Pin0);
        if(CC113L_halRfReceivePacket(RxBuf,&length) == 1)
  {
                Rx_ok = 1;
  }
}
<
回复

使用道具 举报

1

主题

12

回帖

0

蝴蝶豆

初级会员

最后登录
1970-1-1
发表于 2014-7-7 16:11:17 | 显示全部楼层

RE:STM8L的外部中断死循环

你是不是用IAR开发的?把程序Flash 清空,重新编程看看
回复 支持 反对

使用道具 举报

1

主题

3

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2014-7-7 17:27:50 | 显示全部楼层

回复:STM8L的外部中断死循环

 不是用IAR开发的, 我用ST公司自己的编译器。
回复 支持 反对

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2014-7-8 10:47:00 | 显示全部楼层

RE:STM8L的外部中断死循环

如果一直死到中断中,要么是中断标志位没有清除成功,要么就是中断一直发生,建议用上升沿或者下降沿触发中断.
回复 支持 反对

使用道具 举报

1

主题

3

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2014-7-8 11:25:31 | 显示全部楼层

回复:STM8L的外部中断死循环

 我在中断中有清标志位,中断触发方式也选择为上升沿或者下降沿。至于中断一直被触发,我觉得可能性很小,因为我初始化后,执行中断初始化,就不行进入中断
回复 支持 反对

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2014-7-8 14:53:07 | 显示全部楼层

RE:STM8L的外部中断死循环

可以用示波器看看中断引脚的波形。另外,从我说的几个方面去排除一下,这样就能确定是哪儿引起的了。先配置中断向量,再配置中断开启。
回复 支持 反对

使用道具 举报

2

主题

295

回帖

0

蝴蝶豆

初级会员

最后登录
2018-4-6
发表于 2014-7-12 08:55:44 | 显示全部楼层

RE:STM8L的外部中断死循环

仿真看看各个寄存器的值,那个不对,中断标志位运行中清了么,还是一直还在
回复 支持 反对

使用道具 举报

24

主题

514

回帖

6

蝴蝶豆

金牌会员

最后登录
2019-4-8
发表于 2014-7-12 15:02:04 | 显示全部楼层

RE:STM8L的外部中断死循环

仿真一下,看一下相关寄存器的值,问题就一目了然了,祝你好运
回复 支持 反对

使用道具 举报

2

主题

10

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2014-7-16 15:05:35 | 显示全部楼层

回复:STM8L的外部中断死循环

不懂,但给你顶下,希望有其他高手能够看到帮你解决哈
回复 支持 反对

使用道具 举报

1

主题

3

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2014-7-16 17:54:15 | 显示全部楼层

RE:STM8L的外部中断死循环

这个问题一直没解决,但是我换到PB2口就没问题了。还是同样的设置,同样的程序。
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版