MSP430汇编中BUTTON_ISR用jmp后按键仅生效一次问题排查
Got it, let's walk through why your BUTTON_ISR stops working after the first press (when switching to mode 1) — your hunch about jump instructions interacting with the ISR is on the right track, but the root cause is likely tied to interrupt context management or interrupt flag handling.
最可能的故障原因及排查点
1. 中断标志位未清除(最常见)
Most MCUs use edge-triggered external interrupts that set a flag when triggered. If your ISR doesn't manually clear this flag after handling the interrupt, the hardware will think the interrupt is still active and won't respond to subsequent presses. This is the #1 reason for one-time-only interrupts.
Fix: Add code in your ISR to explicitly clear the button interrupt flag. For example (pseudocode):
BUTTON_ISR: ; ... 保存寄存器上下文 ... ; 强制清除中断标志(根据你的MCU手册找对应寄存器) MOV INT_FLAG_REG, #0 INC r9 ; ... 恢复上下文 ... RETI
2. ISR上下文保存/恢复错误
If you don't properly save and restore registers (like the program counter, status register, or other registers used in the ISR) before modifying values or jumping, the main program's flow can get corrupted. This might cause the ISR to fail to return correctly, leaving the system in a state where subsequent interrupts can't trigger.
Check:
- At the start of your ISR, push all registers you modify (plus critical ones like the status register) onto the stack.
- At the end, pop them back in reverse order, then use
RETI(not justRET) to return —RETIrestores the interrupt enable state that was active before the interrupt fired.
3. 主程序循环关闭了全局中断
If your red LED blink loop uses a CLI (clear interrupt enable) instruction or disables interrupts for some reason, the button interrupt won't be able to trigger even if you press the key. This would explain why after switching to mode 1 (blink loop), the button stops responding.
Fix: Audit your RED_LED_BLINK loop and remove any interrupt-disabling code. If you need to disable interrupts briefly for critical sections, make sure to re-enable them quickly so interrupts can be serviced.
4. jumpi破坏了中断向量或程序流程
While less likely, if your jumpi instruction is jumping to an incorrect memory address, it could overwrite the interrupt vector table or corrupt the ISR entry point. This would cause the interrupt to fail after the first jump.
Check: Verify that the addresses passed to jumpi are correct and don't overlap with interrupt vector memory or ISR code.
快速验证步骤
- First, add the interrupt flag clear code to your ISR — this fixes 90% of one-time interrupt issues.
- Check that your ISR uses
RETIinstead ofRETto return. - Ensure your blink loop doesn't disable interrupts.
内容的提问来源于stack exchange,提问作者Tyler

