This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

使用MSP430FR2033,Debug正常,但单独上电异常

Other Parts Discussed in Thread: MSP430FR2033

我在调试MSP430FR2033的按键时发现一个很奇怪的问题,我在Debug时可以正常进入按键中断(下降沿触发),但烧录好了之后单独上电就是无法进入中断。我debug没有设置任何断点,直接点击的运行。

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

    initGpio();

    cs_init();

    //uart_init();

    limit_int_en();

    bat_info_init();

    angle_info_init();

    vent_self_test();

    rtc_wake_isr();

    while (1) {
        angle_test();
    }

}

void limit_int_en(void)
{
    P2IFG &= ~(BIT4 | BIT5);    //clear P2IFGs
    P2IE |= BIT4 | BIT5;
}
void vent_self_test(void)
{
    __bis_SR_register(GIE);     // General interrupt enable

    delay_hw_s(10);

    vent_info_init();

    angle_en();

    timer_start();

    motor_init(motor_stop, 10000, 75);
    pwm_init();

    if (!((P2IN & BIT4) == 0)) {
        vent_open();
        while (vent.limit_open_flag == ERROR) {
            limit_error();
        }
    }

    vent_close();
    while (vent.limit_close_flag == ERROR) {
        limit_error();
    }

    if (vent.limit_open_flag == ERROR) {
        vent_open();
        while (vent.limit_open_flag == ERROR) {
            limit_error();
        }
    }

    vent.init_flag = OK;

    timer_end();

    Angle_correction();

    angle_off();
}
// Port 2 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT1_VECTOR))) Port_2 (void)
#else
#error Compiler not supported!
#endif
{
    switch (P2IFG) {
    case BIT0:
        P2IFG &= ~BIT0;
        break;
    case BIT1:
        P2IFG &= ~BIT1;
        break;
    case BIT2:
        P2IFG &= ~BIT2;
        break;
    case BIT3:
        P2IFG &= ~BIT3;
        break;
    case BIT4:      /* P2.4 is LIMIT1 (Vent open), Falling edge*/
        P2IFG &= ~BIT4;
        //__delay_cycles(10000);             // Delay for n*(1/MCLK(8000000)=0.1s
        //if (!(P2IN & BIT4)) {
            if (motor.motor_flag == open_flag) {
                motor_stop_operate();
                motor.stop_flag = open_limit_stop;
                if (vent.limit_open_flag == ERROR) {
                    angle.value_open = read_angle_value();
                    vent.limit_open_flag = OK;
                }
                led_off();
                green_on();
            }
        //}
        break;

    case BIT5:      /* P2.5 is LIMIT2(Vent close), Falling edge*/
        P2IFG &= ~BIT5;
        //__delay_cycles(10000);             // Delay for n*(1/MCLK(8000000)=0.1s
        //if (!(P2IN & BIT5)) {
            if (motor.motor_flag == close_flag) {
                motor_stop_operate();
                motor.stop_flag = close_limit_stop;
                if (vent.limit_close_flag == ERROR) {
                    angle.value_close = read_angle_value();
                    vent.limit_close_flag = OK;
                }
                led_off();
                blue_on();
            }
        //}
        break;

    case BIT6:
        P2IFG &= ~BIT6;
        break;
    case BIT7:
        P2IFG &= ~BIT7;
        break;
    default: break;
    }
}

后面我单独对按键进行了测试,发现问题点是在开始时单独对中断标志位清0,还是对P2整个中断标志清0上,如果单独对你需要用的中断清0的话,debug正常,但单独上电异常,难道是单独上电时其他中断标志位初始值不为0?

下面是我的测试代码

/* --COPYRIGHT--,BSD_EX
 * Copyright (c) 2014, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *******************************************************************************
 *
 *                       MSP430 CODE EXAMPLE DISCLAIMER
 *
 * MSP430 code examples are self-contained low-level programs that typically
 * demonstrate a single peripheral function or device feature in a highly
 * concise manner. For this the code may rely on the device's power-on default
 * register values and settings such as the clock configuration and care must
 * be taken when combining code from several examples to avoid potential side
 * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
 * for an API functional library-approach to peripheral configuration.
 *
 * --/COPYRIGHT--*/
//******************************************************************************
//  MSP430FR413x Demo - Software Port Interrupt Service on P1.3 from LPM3
//
//  Description: A Hi/Lo transition on P1.3 will trigger P1ISR the first time.
//  On hitting the P1ISR, device exits LPM3 mode and executes section of code in
//  main() which includes toggling an LED.
//
//  ACLK = default REFO ~32768Hz, MCLK = SMCLK = default DCODIV ~1MHz.
//
//
//              MSP430FR4133
//            ---------------
//        /|\|               |
//         | |               |
//         --|RST            |
//     /|\   |               |
//      --o--|P1.3       P1.0|-->LED
//     \|/   |               |
//           |               |
//
//   Cen Fang
//   Wei Zhao
//   Texas Instruments Inc.
//   Oct 2013
//   Built with IAR Embedded Workbench v5.60 & Code Composer Studio v5.5
//******************************************************************************

#include <msp430.h>

#include "gpio.h"

#include "led.h"


int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

    initGpio();
    
#if (1)
    P2IFG = 0x0;    //clear P2IFGs,it is good.
    //P2IFG &= ~(BIT4 | BIT5);    //clear P2.4,P2.5IFGs ,it is bad.
    P2IE |= BIT4 | BIT5;
#endif

#if (0)
    P2IFG = 0x0;    //clear P2IFGs
    P2IE = 0x30;
#endif
    
    while(1)
    {
        __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/interrupt
        __no_operation();                   // For debugger

    }
}

// Port 2 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT1_VECTOR))) Port_2 (void)
#else
#error Compiler not supported!
#endif
{
    switch (P2IFG) {
    case BIT0:
        P2IFG &= ~BIT0;
        break;
    case BIT1:
        P2IFG &= ~BIT1;
        break;
    case BIT2:
        P2IFG &= ~BIT2;
        break;
    case BIT3:
        P2IFG &= ~BIT3;
        break;
    case BIT4:      /* P2.4 is LIMIT1 (Vent open), Falling edge*/
        P2IFG &= ~BIT4;

                led_off();
                green_on();

        break;

    case BIT5:      /* P2.5 is LIMIT2(Vent close), Falling edge*/
        P2IFG &= ~BIT5;

                led_off();
                blue_on();

        break;

    case BIT6:
        P2IFG &= ~BIT6;
        break;
    case BIT7:
        P2IFG &= ~BIT7;
        break;
    default: break;
    }
}