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.

[参考译文] MSP430F5529:MSP430F5529 ISR 问题

Guru**** 2524550 points
Other Parts Discussed in Thread: MSP-EXP430F5529LP

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1044938/msp430f5529-msp430f5529-isr-question

器件型号:MSP430F5529
主题中讨论的其他器件:MSP-EXP430F5529LP

大家好、我不熟悉嵌入式编程。 我从 MSP-EXP430F5529LP 开始、并尝试关注   Chris Svec 的博客系列 embedded.fm/.../ese101

在他的一个博客(embedded.fm/.../ese101-interrupts-blink)中、作者使用 ISR (通过按钮开关 GPIO 1.1触发)使 LED (GPIO 1.0)闪烁。 我遵循他成功完成的操作、然后我想创建另一个 ISR、以使用另一个按钮开关(GPIO 2.1)使另一个 LED (GPIO 4.7)闪烁。

以下是我在汇编语言中的代码:

;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------
; Set GPIO P1.0 to be an output (P1DIR bit 0 == 1)
BIS.B #0x01, &P1DIR
; Set GPIO P1.1 to be an input (P1DIR bit 1 == 0)
BIC.B #0x02, &P1DIR
; Set GPIO P1.1 to be pulled up or down (P1REN bit 1 == 1)
BIS.B #0x02, &P1REN
; Set GPIO P1.1 as a pull-up resistor (P1OUT bit 1 == 1)
BIS.B #0x02, &P1OUT

; Set interrupt on high-to-low transition of P1.1
BIS.B #0x02, &P1IES
; Clear any interrupts that happened when changing P1IES
BIC.B #0x02, &P1IFG
; Enable P1.1 interrupts
BIS.B #0x02, &P1IE
;-------------------------------------------------------------------------------
; Set GPIO P4.7 to be an output (P4DIR bit 7 == 1)
BIS.B #0x80, &P4DIR
; Set GPIO P2.1 to be an input (P2DIR bit 1 == 0)
BIC.B #0x02, &P2DIR
; Set GPIO P2.1 to be pulled up or down (P2REN bit 1 == 1)
BIS.B #0x02, &P2REN
; Set GPIO P2.1 as a pull-up resistor (P2OUT bit 1 == 1)
BIS.B #0x02, &P2OUT

; Set interrupt on high-to-low transition of P2.1
BIS.B #0x02, &P2IES
; Clear any interrupts that happened when changing P2IES
BIC.B #0x02, &P2IFG
; Enable P2.1 interrupts
BIS.B #0x02, &P2IE

; Enable interrupts
NOP ; the user’s guide recommends a NOP before setting #GIE
BIS #GIE, SR
NOP ; the user’s guide recommends a NOP after setting #GIE

BIC.W #0x01, &P1OUT
BIC.W #0x80, &P4OUT


MainLoop: ; infinite loop that does nothing
JMP MainLoop
NOP

PORT1_ISR:
; Clear the interrupt flag.
BIC #0x02, &P1IFG
; Toggle GPIO P1.0
XOR.B #0x01, &P1OUT
RETI

PORT2_ISR:
; Clear the interrupt flag.
BIC #0x02, &P2IFG
; Toggle GPIO P4.7
XOR.B #0x80, &P4OUT
RETI

;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack

;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
.sect ".int47" ; We added these two lines
.short PORT1_ISR ; for configuring our GPIO Port P1 ISR.

.sect ".int42"
.short PORT2_ISR

当我在评估板上运行代码时、 它能够完美地适用于 Port1_ISR:。 ISR PORT1_ISR:  GPIO 1.1 被接合时执行。 ISR 完成后、它返回到 MainLoop。 但是、当我尝试 port2_ISR 时、GPIO 2.1会触发 ISR、但在完成后、它不会返回到 MainLoop。 相反、它会无限期地在该 ISR 中循环。 我在这里有什么问题吗?

谢谢

Yi

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我再播放一点、看起来寄存器 P2IFG1从未被清除、即使按下按钮开关被释放也是如此。 如果我在 CCS 的"Register"窗口中手动将其清除、ISR 将返回其应有的状态。 是否知道为什么这个位没有被清除?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    更多信息、我注意到 GPIO 2.1可用于由寄存器 P2SEL 控制的其他功能、因此我在代码中添加了以下语句、但这并不会产生任何影响:

    BIS.B      #0x00, &P2SEL

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    > BIC #0x02、&P2IFG

    我想你需要

    > BIC.B #0x02、&P2IFG

    隐含的 BIC.W 从地址上的字中读取、而 P2IFG 在0x1D 上、因此它在地址0x001C 上清除0x02。

    P1IFG 基准也应为 BIC.B、但由于 P1IFG 的地址是字对齐(0x001C)、因此它会意外工作

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    事实上,它解决了我的问题。 应该对此给予更多关注。 谢谢。