请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
部件号:MSP430FR5994 主题中讨论的其他部件:MSP-EXP430FR5994
我正在为 MSP430FR5994 (特别是 MSP-EXP430FR5994)编写一些代码,并且我正在按照 示例代码发送PC信号并返回。 为了使用EXP板上的USB端口,我需要将UART引脚从WFP 6.0 和6.1 更改为2.0 WFP和WFP 2.1。 下面是我为实现此目标而更改的代码。
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog
// Configure GPIO
P2SEL0 &= ~(BIT0 | BIT1);
P2SEL1 |= (BIT0 | BIT1); // USCI_A0 UART operation (p93_s)
P6SEL1 &= ~(BIT0 | BIT1);
P6SEL0 |= (BIT0 | BIT1); // USCI_A3 UART operation (p109_s)
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Startup clock system with max DCO setting ~8MHz
CSCTL0_H = CSKEY_H; // Unlock CS registers
CSCTL1 = DCOFSEL_3 | DCORSEL; // Set DCO to 8MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
CSCTL0_H = 0; // Lock CS registers
// Configure USCI_A3 for UART mode
//UCA3CTLW0 = UCSWRST; // Put eUSCI in reset (p788)
//UCA3CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
// Baud Rate calculation
// 8000000/(16*9600) = 52.083
// Fractional portion = 0.083
// User's Guide Table 21-4: UCBRSx = 0x04
// UCBRFx = int ( (52.083-52)*16) = 1
//UCA3BRW = 52; // 8000000/16/9600, BRW = Baud Rate Ctrl Word Register, p789
//UCA3MCTLW |= UCOS16 | UCBRF_1 | 0x4900; // UCOS16 = Oversampling enable, used when high frequency clk is used, probably divides everything by 16, UCBRF = fine turner when UCOS16 is active
// 0x4900 is for first 8 bits,
//UCA3CTLW0 &= ~UCSWRST; // Initialize eUSCI
//UCA3IE |= UCRXIE; // Enable USCI_A3 RX interrupt
// Configure USCI_A0 for UART mode
UCA0CTLW0 = UCSWRST; // Put eUSCI in reset (p788)
UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
// Baud Rate calculation for 19200
// 8000000/(16*19200) = 26.042
// Fractional portion = 0.042
// User's Guide Table 21-4: UCBRSx = 0x04
// UCBRFx = int ( (52.083-52)*16) = 1
UCA0BRW = 52; // 8000000/16/9600, BRW = Baud Rate Ctrl Word Register, p789
UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900; // UCOS16 = Oversampling enable, used when high frequency clk is used, probably divides everything by 16, UCBRF = fine turner when UCOS16 is active
// 0x4900 is for first 8 bits,
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM3_bits | GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=EUSCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(EUSCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA0IFG&UCTXIFG)); //While the A0 flag and TX flag are not both active
UCA0TXBUF = UCA0RXBUF;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=EUSCI_A3_VECTOR
__interrupt void USCI_A3_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(EUSCI_A3_VECTOR))) USCI_A3_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA3IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA3IFG&UCTXIFG)); //While the A3 flag and TX flag are not both active
UCA3TXBUF = UCA3RXBUF;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
但是,我无法使用Termite将字符从我的PC传输到主板。 使用引脚6.0 和6.1 测试系统,并将GPIO引脚连接到J101引脚,这样可以有效地更改引脚。