求助 关于ARM M3 中断问题



#include "hw_memmap.h"

#include "hw_ints.h"

#include "hw_nvic.h"

#include "hw_types.h"

#include "interrupt.h"

#include "sysctl.h"

#include "gpio.h"

#define LED3 GPIO_PIN_6

#define KEY3 GPIO_PIN_4

#define PINS    GPIO_PIN_5

void delay(int d)//延时函数

{

   for( ; d; --d);

}

int main()

{

 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

  GPIOPadConfigSet(GPIO_PORTB_BASE, PINS,

                    GPIO_STRENGTH_4MA,

                    GPIO_PIN_TYPE_STD);//配置管脚驱动,驱动电流2MA其实已足够

   GPIODirModeSet(GPIO_PORTB_BASE, PINS, GPIO_DIR_MODE_OUT);//设置管脚输出

GPIOPadConfigSet(GPIO_PORTB_BASE,KEY3,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

 GPIODirModeSet(GPIO_PORTB_BASE,KEY3,GPIO_DIR_MODE_IN);

 IntMasterEnable();

// IntEnable(INT_GPIOB);  //使能B端口中断

GPIOIntTypeSet(GPIO_PORTB_BASE,KEY3,GPIO_FALLING_EDGE); //下降沿中断

// GPIOPinIntEnable(GPIO_PORTB_BASE,KEY3);    //使能中断

   while(1) {

             GPIOPinWrite(GPIO_PORTB_BASE, PINS, PINS);//输出高电平

             delay(20000);//延时

             GPIOPinWrite(GPIO_PORTB_BASE, PINS, ~PINS);//输出低电平

             delay(20000);//延时

   }  

}

void GPIO_Port_B_ISR(void)

{

long IntStatus;

IntStatus=GPIOPinIntStatus(GPIO_PORTB_BASE,true);

GPIOPinIntClear(GPIO_PORTB_BASE,IntStatus);

if(IntStatus&KEY3)  {

  GPIOPinWrite(GPIO_PORTB_BASE,LED3,LED3^GPIOPinRead(GPIO_PORTB_BASE,LED3));

}

}

// IntEnable(INT_GPIOB);  //使能B端口中断

// GPIOPinIntEnable(GPIO_PORTB_BASE,KEY3);    //使能中断

为什么要屏蔽这两个才能进入死循环 while(1)

如果不屏蔽的话死循环的点灯就不会执行  且中断也没反应。

不知道 是不是哪设置的不对啊!

是在PROTEUS仿真下试验的

  •  startup_ewarm.c 的配置如下

     

     

    //*****************************************************************************

    //

    // startup_ewarm.c - Startup code for use with IAR's Embedded Workbench,

    //                   version 5.

    //

    // Copyright (c) 2006-2012 Texas Instruments Incorporated.  All rights reserved.

    // Software License Agreement

    //

    // Texas Instruments (TI) is supplying this software for use solely and

    // exclusively on TI's microcontroller products. The software is owned by

    // TI and/or its suppliers, and is protected under applicable copyright

    // laws. You may not combine this software with "viral" open-source

    // software in order to form a larger program.

    //

    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.

    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT

    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY

    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL

    // DAMAGES, FOR ANY REASON WHATSOEVER.

    //

    // This is part of revision 8555 of the EK-LM3S811 Firmware Package.

    //

    //*****************************************************************************

    //*****************************************************************************

    //

    // Enable the IAR extensions for this source file.

    //

    //*****************************************************************************

    #pragma language=extended

    //*****************************************************************************

    //

    // Forward declaration of the default fault handlers.

    //

    //*****************************************************************************

    void ResetISR(void);

    static void NmiSR(void);

    static void FaultISR(void);

    static void IntDefaultHandler(void);

    void GPIO_Port_B_ISR(void);   //没加 extern 关键字

    //*****************************************************************************

    //

    // The entry point for the application startup code.

    //

    //*****************************************************************************

    extern void __iar_program_start(void);

    //*****************************************************************************

    //

    // Reserve space for the system stack.

    //

    //*****************************************************************************

    static unsigned long pulStack[64] @ ".noinit";

    //*****************************************************************************

    //

    // A union that describes the entries of the vector table.  The union is needed

    // since the first entry is the stack pointer and the remainder are function

    // pointers.

    //

    //*****************************************************************************

    typedef union

    {

       void (*pfnHandler)(void);

       unsigned long ulPtr;

    }

    uVectorEntry;

    //*****************************************************************************

    //

    // The vector table.  Note that the proper constructs must be placed on this to

    // ensure that it ends up at physical address 0x0000.0000.

    //

    //*****************************************************************************

    __root const uVectorEntry __vector_table[] @ ".intvec" =

    {

       { .ulPtr = (unsigned long)pulStack + sizeof(pulStack) },

    //   __iar_program_start,                                        // The initial stack pointer

       ResetISR,                               // The reset handler

       NmiSR,                                  // The NMI handler

       FaultISR,                               // The hard fault handler

       IntDefaultHandler,                      // The MPU fault handler

       IntDefaultHandler,                      // The bus fault handler

       IntDefaultHandler,                      // The usage fault handler

       0,                                      // Reserved

       0,                                      // Reserved

       0,                                      // Reserved

       0,                                      // Reserved

       IntDefaultHandler,                      // SVCall handler

       IntDefaultHandler,                      // Debug monitor handler

       0,                                      // Reserved

       IntDefaultHandler,                      // The PendSV handler

       IntDefaultHandler,                      // The SysTick handler

       IntDefaultHandler,                      // GPIO Port A

       GPIO_Port_B_ISR,                      // GPIO Port B

       IntDefaultHandler,                      // GPIO Port C

       IntDefaultHandler,                      // GPIO Port D

       IntDefaultHandler,                      // GPIO Port E

       IntDefaultHandler,                      // UART0 Rx and Tx

       IntDefaultHandler,                      // UART1 Rx and Tx

       IntDefaultHandler,                      // SSI0 Rx and Tx

       IntDefaultHandler,                      // I2C0 Master and Slave

       IntDefaultHandler,                      // PWM Fault

       IntDefaultHandler,                      // PWM Generator 0

       IntDefaultHandler,                      // PWM Generator 1

       IntDefaultHandler,                      // PWM Generator 2

       IntDefaultHandler,                      // Quadrature Encoder 0

       IntDefaultHandler,                      // ADC Sequence 0

       IntDefaultHandler,                      // ADC Sequence 1

       IntDefaultHandler,                      // ADC Sequence 2

       IntDefaultHandler,                      // ADC Sequence 3

       IntDefaultHandler,                      // Watchdog timer

       IntDefaultHandler,                      // Timer 0 subtimer A

       IntDefaultHandler,                      // Timer 0 subtimer B

       IntDefaultHandler,                      // Timer 1 subtimer A

       IntDefaultHandler,                      // Timer 1 subtimer B

       IntDefaultHandler,                      // Timer 2 subtimer A

       IntDefaultHandler,                      // Timer 2 subtimer B

       IntDefaultHandler,                      // Analog Comparator 0

       IntDefaultHandler,                      // Analog Comparator 1

       IntDefaultHandler,                      // Analog Comparator 2

       IntDefaultHandler,                      // System Control (PLL, OSC, BO)

       IntDefaultHandler                       // FLASH Control

    };

    //*****************************************************************************

    //

    // This is the code that gets called when the processor first starts execution

    // following a reset event.  Only the absolutely necessary set is performed,

    // after which the application supplied entry() routine is called.  Any fancy

    // actions (such as making decisions based on the reset cause register, and

    // resetting the bits in that register) are left solely in the hands of the

    // application.

    //

    //*****************************************************************************

    void

    ResetISR(void)

    {

       //

       // Call the application's entry point.

       //

       __iar_program_start();

    }

    //*****************************************************************************

    //

    // This is the code that gets called when the processor receives a NMI.  This

    // simply enters an infinite loop, preserving the system state for examination

    // by a debugger.

    //

    //*****************************************************************************

    static void

    NmiSR(void)

    {

       //

       // Enter an infinite loop.

       //

       while(1)

       {

       }

    }

    //*****************************************************************************

    //

    // This is the code that gets called when the processor receives a fault

    // interrupt.  This simply enters an infinite loop, preserving the system state

    // for examination by a debugger.

    //

    //*****************************************************************************

    static void

    FaultISR(void)

    {

       //

       // Enter an infinite loop.

       //

       while(1)

       {

       }

    }

    //*****************************************************************************

    //

    // This is the code that gets called when the processor receives an unexpected

    // interrupt.  This simply enters an infinite loop, preserving the system state

    // for examination by a debugger.

    //

    //*****************************************************************************

    static void

    IntDefaultHandler(void)

    {

       //

       // Go into an infinite loop.

       //

       while(1)

       {

       }

    }

  • fanhuaming fanhuaming :

    这是全部的代码?怎么连时钟设置都没有呀

  • 楼主检查下你中断向量表中中断的位置,看看是否正确,有可能跑到别的中断里去了

    可以不用startup代码,参考driverlib的例程写一个试试:

    int iVal;

    //

    // Register the port-level interrupt handler. This handler is the

    // first level interrupt handler for all the pin interrupts.

    //

    GPIOPortIntRegister(GPIO_PORTA_BASE, PortAIntHandler);

    //

    // Initialize the GPIO pin configuration.

    //

    // Set pins 2, 4, and 5 as input, SW controlled.

    //

    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,

    GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);

    //

    // Set pins 0 and 3 as output, SW controlled.

    //

    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_3);

    //

    // Make pins 2 and 4 rising edge triggered interrupts.

    //

    GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4, GPIO_RISING_EDGE);

    //

    // Make pin 5 high level triggered interrupts.

    //

    GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_HIGH_LEVEL);

    //

    // Read some pins.

    //

    iVal = GPIOPinRead(GPIO_PORTA_BASE,

    (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 |

    GPIO_PIN_4 | GPIO_PIN_5));

    //

    // Write some pins. Even though pins 2, 4, and 5 are specified, those

    // pins are unaffected by this write because they are configured as inputs.

    // At the end of this write, pin 0 will be a 0, and pin 3 will be a 1.

    //

    GPIOPinWrite(GPIO_PORTA_BASE,

    (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 |

    GPIO_PIN_4 | GPIO_PIN_5),

    0xF8);

    //

    // Enable the pin interrupts.

    //

    GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);

  • 问题解决了,中断跟Backup of driverlib.a 也是有关系的。

    我用TI函数库中的D:\StellarisWare\driverlib\ewarm-cm3\Exe\driverlib-cm3.a这个文件一直进不了中断。。后来按照周立功的做法用IAR得新生成的Backup of driverlib.a 进中断可以。。

  • fanhuaming :

      这种软件仿真的很多东西不可信。。。