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.

[参考译文] MSP-EXP430FR5994:GCC UART 通信不工作

Guru**** 2524550 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1196467/msp-exp430fr5994-gcc-uart-communication-not-working

器件型号:MSP-EXP430FR5994

您好!

我尝试通过 UART 发送串行数据。 程序卡在循环中。 有什么想法吗?

谢谢、EDI

#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>

#define TXLED BIT0
#define RXLED BIT1
#define TXD BIT0
#define RXD BIT1

int main(void)
{
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

    // Configure one FRAM waitstate as required by the device datasheet for MCLK
    // operation beyond 8MHz _before_ configuring the clock system.
    FRCTL0 = FRCTLPW | NWAITS_1;

    // Clock System Setup
    CSCTL0_H = CSKEY_H;                                  // Unlock CS registers
    CSCTL1 = DCOFSEL_0;                                  // Set DCO to 1MHz
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO, ACLK = VLOCLK

    // Per Device Errata set divider to 4 before changing frequency to
    // prevent out of spec operation from overshoot transient
    CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4; // Set all corresponding clk sources to divide by 4 for errata
    CSCTL1 = DCOFSEL_4 | DCORSEL;         // Set DCO to 16MHz

    // Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz))
    __delay_cycles(60);
    CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 for 16MHz operation
    CSCTL0_H = 0;                         // Lock CS registers

    // Init UART
    UCA0CTL1 = UCSWRST;       // Stop UART
    UCA0BR0 = 104;            // 9600bps @16MHz
    UCA0BR1 = 2;              // 9600bps @16MHz
    UCA0MCTLW = 0x49;         // 9600bps @16MHz
    UCA0CTL1 = UCSSEL__SMCLK; // Start UART, connect it to SMCLK

    // Init Pins
    PM5CTL0 &= ~LOCKLPM5; // Enable ports
    P2SEL0 |= TXD | RXD;  // Set tertiary pin function on UART pins
    P2SEL1 |= TXD | RXD;  // set tertiary pin function on uart pins
    P1DIR |= BIT0;        // Configure P1.0 as output (LED)
    P1OUT |= BIT0;        // Set P1.0 (LED on)
    __delay_cycles(16e6); // Delay about a second
    P1OUT &= ~BIT0;       // Clear P1.0 (LED off)

    while (true)
    {
        __delay_cycles(16e5); // Delay about 0.1s
        P1OUT |= BIT0;        // Set P1.0 (LED on)
        while (!(UCA0IFG & UCTXCPTIFG))
            ;                 // Check if TX is ready
        __delay_cycles(16e5); // Delay about 0.1s
        P1OUT &= ~BIT0;       // Clear P1.0 (LED off)
        UCA0TXBUF = 'x';      // Transmit an 'x'
    }
}

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

    您使用了错误标志。 在移出某些内容并在发送任何内容之前对其进行测试后、UCTXCPTIFG 会被置位。 因此,这一点仍然很清楚。 轮询传输的常见测试是 UCTXIFG。 在器件或串行端口复位后设置。

    我还想知道您的波特率设置。 该器件具有一个16位寄存器 UCA0BRW。 您应该查看用户指南以了解 UCBRx、UCBRFx 和 UCBRSx 的值如何映射到器件寄存器。

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

    谢谢! 我将其更改为  

    while (!(UCA0IFG & UCTXIFG))
    现在它不会挂起。 但不会传输任何内容、我也看不到示波器上的任何内容...
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    >P2SEL0 |= TXD | RXD;//在 UART 引脚上设置第三引脚功能

    根据数据表(SLASE54D)表9-23、对于 UCA0、PSEL0位应该为0。 尝试删除此行。

    --------

    >UCA0BR1 = 2;// 9600bps @16MHz

    当 br0=104时、这是/(512+104)的除数。 如果 UCOS16=1、则为16M/16/616=1623bps。 请尝试:

    >UCA0BR1 = 0;// 9600bps @16MHz

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

    完美,非常感谢! 一切都在进行中!