我在 Launchpad 上装有 MSP430FR2355、我正在尝试使用 PC 通过连接到 USCI_A1的应用 UART 与它进行通信。 此时、我只是想将字符回显到计算机上。 我按如下方式配置 UART:
UCA1CTLW0 |= UCSWRST; // stop UART before configuring
UCA1CTLW0 |= UCSSEL_2; // use SMCLK clock source
/* set the baud rate to 9600 using values from user's guide for 1.048576 MHz BRCLK (baud rate clock)
*
* UCOS16 = 1 (lowest bit of UCA1MCTLW register)
* UCBRx = 6 (UCA1BRW register)
* UCBRFx = 13 (top half of lower byte of UCA1MCTLW register)
* UCBRSx = 0X22 (upper byte of UCA1MCTLW register)
*
*/
UCA1MCTLW |= 1; // enable oversampling
UCA1BRW = 6;
UCA1MCTLW |= 0x22D0;
UCA1IE |= UCRXIE; // enable interrupt when data is received
UCA1CTLW0 &= ~UCSWRST; // enable UART A1
P4SEL0 |= BIT2 | BIT3; // set UART_A1 pins as second function for Tx and Rx
我无法使用接收中断使它正常工作。 我正在使用的 ISR 根据示例代码进行了调整、以使用正确的 UART 通道- msp430fr235x_euscia0_uart_01.c (TI.com)。我添加了 LED 引脚的切换、以查看是否 调用了 ISR、它看起来根本没有调用。 我可以通过轮询 UCA1IFG 寄存器使其正常运行、但更愿意使用中断。
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
P1OUT ^= 0x01;
switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF = UCA1RXBUF;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
我做错了什么事吗?
谢谢