TI中文支持网
TI专业的中文技术问题搜集分享网站

cc430串口接收中断无法跳出

#include "cc430x613x.h"
#include "stdint.h"

uint8_t data[4]={0x00};

void main(void){
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

PMAPPWD = 0x02D52; // Get write-access to port mapping regs P2MAP6 = PM_UCA0RXD; // Map UCA0RXD output to P2.6 P2MAP7 = PM_UCA0TXD; // Map UCA0TXD output to P2.7 PMAPPWD = 0; // Lock port mapping registers

P1DIR |= BIT6; // Set P2.7 as TX output
P1SEL |= BIT5 + BIT6; // Select P2.6 & P2.7 to UART function

UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger

__no_operation();
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 – no interrupt
case 2: // Vector 2 – RXIFG
// while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?

data[0]= UCA0RXBUF; // TX -> RXed character
UCA0IE= 0x00; break;
case 4:break; // Vector 4 – TXIFG
default: break; }
__bic_SR_register(LPM3_bits); // Enter LPM3, interrupts enabled
}

首先可以确定这里的波特率等参数设置都是正确的,而且这段程序可以顺利进入中断,但是无法跳出中断执行到主程序中的第二个“__no_operation();”处(我在那里设置了断点),程序全速运行后,用串口调试助手向单片机写入数字,若断点设置在中断服务程序内则可以看到调试助手发送的数字被赋给了data[0]。请问如何正确跳出该中断?

我检查后发现第二功能配置的两句有问题,和硬件对不上可串口自收发居然是可以的……把程序往正确方向改成如下程序还是跳不出中断:

#include "cc430x613x.h"
#include "stdint.h"

uint8_t data[4]={0x00};

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
PMAPPWD = 0x02D52; // Get write-access to port mapping regs P1MAP5 = PM_UCA0RXD; // Map UCA0RXD output to P2.6 P1MAP6 = PM_UCA0TXD; // Map UCA0TXD output to P2.7 PMAPPWD = 0; // Lock port mapping registers P1DIR |= BIT6; // Set P2.7 as TX output
P1SEL |= BIT5 + BIT6; // Select P2.6 & P2.7 to UART function
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM0_bits+GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger

__no_operation();
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 – no interrupt
case 2: // Vector 2 – RXIFG
// while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
data[0]= UCA0RXBUF; // TX -> RXed character
UCA0IE &= ~ UCRXIE; break;
case 4:break; // Vector 4 – TXIFG
default: break; }
__bic_SR_register(LPM0_bits); // Enter LPM3, interrupts enabled
}

请问这是为什么?

Jeanne Yi:

您好!

建议您将main()函数第二个__no_operation();做以下修改:

while(1){

__no_operation();

};

谢谢!

赞(0)
未经允许不得转载:TI中文支持网 » cc430串口接收中断无法跳出
分享到: 更多 (0)