我目前正在使用 msp430fr2433开发门磁性开关。(环境:CCS10.4.0)
首先,我尝试使用 driverlib 来加速我的开发。 由于启动板上的两个按钮与 P2.3和 P2.7相关联,示例代码上周运行良好,我认为它很简单。
但是,我自己的硬件上还有一个与 P1.1链接的按钮。 我尝试修改这样的代码。
void main (void)
{
//Stop watchdog timer
WDT_A_hold(WDT_A_BASE);
//Set LED to output direction
GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0 + GPIO_PIN1);
//Set LED pins HI
GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN0 + GPIO_PIN1);
//Enable S1,S2 internal resistance as pull-Up resistance
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1,GPIO_PIN5);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2,GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN7);
//S1,S2 interrupt enabled
GPIO_enableInterrupt(GPIO_PORT_P1,GPIO_PIN5);
GPIO_enableInterrupt(GPIO_PORT_P2,GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN7);
//S1 Hi/Lo edge
GPIO_selectInterruptEdge(GPIO_PORT_P1,GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN7,GPIO_HIGH_TO_LOW_TRANSITION);
//S1 IFG cleared
GPIO_clearInterrupt(GPIO_PORT_P1,GPIO_PIN5);
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN7);
PMM_unlockLPM5();
//Enter LPM3 w/interrupt
__bis_SR_register(LPM3_bits + GIE);
//For debugger
__no_operation();
}
#if GPIO_PORT_S1 == GPIO_PORT_P1
//******************************************************************************
//
//This is the PORT1_VECTOR interrupt vector service routine
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(PORT1_VECTOR)))
#endif
void P1_ISR (void)
{
__delay_cycles(10000);
GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0 + GPIO_PIN1);
GPIO_clearInterrupt(GPIO_PORT_P1,GPIO_PIN5);
}
#elif GPIO_PORT_S1 == GPIO_PORT_P2
//******************************************************************************
//
//This is the PORT2_VECTOR interrupt vector service routine
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(PORT2_VECTOR)))
#endif
void P2_ISR (void)
#endif // #if GPIO_PORT_S1
{
__delay_cycles(10000);
if (GPIO_getInterruptStatus(GPIO_PORT_P2 , GPIO_PIN2))
{
GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0 + GPIO_PIN1);
if (GPIO_INPUT_PIN_HIGH == GPIO_getInputPinValue(GPIO_PORT_P2 , GPIO_PIN2))
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN2,GPIO_HIGH_TO_LOW_TRANSITION);
}
else
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN2,GPIO_LOW_TO_HIGH_TRANSITION);
}
}
if (GPIO_getInterruptStatus(GPIO_PORT_P2 , GPIO_PIN3))
{
GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0);
if (GPIO_INPUT_PIN_HIGH == GPIO_getInputPinValue(GPIO_PORT_P2 , GPIO_PIN3))
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN3,GPIO_HIGH_TO_LOW_TRANSITION);
}
else
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN3,GPIO_LOW_TO_HIGH_TRANSITION);
}
}
if (GPIO_getInterruptStatus(GPIO_PORT_P2 , GPIO_PIN7))
{
GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN1);
if (GPIO_INPUT_PIN_HIGH == GPIO_getInputPinValue(GPIO_PORT_P2 , GPIO_PIN7))
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN7,GPIO_HIGH_TO_LOW_TRANSITION);
}
else
{
GPIO_selectInterruptEdge(GPIO_PORT_P2,GPIO_PIN7,GPIO_LOW_TO_HIGH_TRANSITION);
}
}
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN2 + GPIO_PIN3+GPIO_PIN7);
}
我已将此代码下载到启动板。 两个新按钮:P2.2和 P1.5,我使用 DuPont 电缆将它们短接到 GND,而不是按按钮。
然后出现了一些问题。 代码运行不好,在调试视图中,代码在 ISR_TRATE.ASM 的 JMP __TI_ISR_TRAP 处停止

我只在调试视图中按“开始”和“挂起”,但没有按硬件上的任何按钮。
我再次尝试使用原始示例,似乎 也是同样的问题。
我还尝试了不带驱动程序库的示例: msp430fr243x_P1_03.c,但也失败了。
我很困惑为什么会发生这种情况,我确信我的电脑在这个周末没有发生任何事情。