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.

[参考译文] MSP430FR2476:MSP430FR2476TRHB UART0 TXD

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1360802/msp430fr2476-msp430fr2476trhb-uart0-txd

器件型号:MSP430FR2476

您好

IC:MSP430FR2476TRHB

UART0:P1.4-TXD0,P1.5--RXD0

UART 0可以进入接收中断、UCA0RXBUF 中的数据是正确的。 单步调试、可以输入发送中断、UCA0TXBUF 中的数据正确、但主机软件无法接收数据。  示波器测试 TXD0端口、无信号输出。

添加 SYSCFG3|=USCIA0RMP;故障依然存在。

主机软件和串行线已排除故障,硬件连接也没有问题。 已尝试多个电路板均为相同故障!

URAT1的配置与 UART0的配置相同、串行端口正常发送和接收数据。

// IO

p1DIR |= 0xff;//将未使用的引脚设置为输出方向
P1SEL0 |= BIT2+BIT4+BIT5;// P1.4-P1.5 UART

//设置 USCI_A0 9600 n 8 1
UCA0CTLW0 |= UCSWRST;//**将状态机置于复位状态**
UCA0CTLW0 |= UCSSEL_2;// SMCLK

// UCA0BR0 = 26;
// UCA0BR1 = 0;
// UCA0MCTLW = 0xB600 | UCOS16 | UCBRF_1;

UCA0BR0 = 52;// 8MHz 9600 (请参阅用户指南)
UCA0BR1 = 0;// 8MHz 9600
UCA0MCTLW = 0x4900 | UCOS16 | UCBRF_1;

UCA0CTLW0 &&~UCSWRST;//**初始化 USCI 状态机**
UCA0IE |= UCRXIE;//启用 USCI_A1 RX 中断

#pragma vector=USCI_A0_vector
__interrupt void USCI_A0_ISR (void)
{
开关(__even_in_range (UCA0IV、4))
{
情形0:中止;//无中断
情形2:// RXIFG
{
RX232_BUFF0[RX23_IndexW0]=UCA0RXBUF;//FIFO
// while ((UCA1IFG&UCRXIFG));

RX232_IndexW0++;
if ((RX232_BUFF0[RX232_IndexW0-2]== 0x0D)&(RX232_BUFF0[RX232_IndexW0-1]== 0x0A))
{
RX232_IndexW0=0;
REC232_FLAG0=1;  

if (RX232_IndexW0 >= RX232BUF_SIZE0)
{
RX232_IndexW0=0;


中断;

情形4:// TXIFG
{
if (TX232_OutLen0>0)//FIFO
{
TX232_OutLen0--;  
UCA0TXBUF= 5232_BUFF0[TX232_IndexR0];
while (! (UCA0IFG&UCTXIFG);
if (++TX232_IndexR0 >= TX232BUF_SIZE0)
{
TX232_IndexR0=0;


否则
{
UCA0IE &=~UCTXIE;  

中断;

默认值:中断;

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

    您能首先尝试一下这个例子吗? 所有这些都使用 UCA0。 如果要更改 GPIO、请检查此代码。  

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2018, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430FR267x Demo - eUSCI_A0 UART echo at 4800 baud using BRCLK = 32768Hz.
    //
    //  Description: This demo echoes back characters received via a PC serial port.
    //  ACLK is used as UART clock source and the device is put in LPM3.
    //  Note that level shifter hardware is needed to shift between RS232 and MSP
    //  voltage levels.
    //
    //  The example code shows proper initialization of registers
    //  and interrupts to receive and transmit data.
    //  To test code in LPM3, disconnect the debugger.
    //
    //  ACLK = REFO = 32768Hz, MCLK = SMCLK = DCODIV ~1MHz.
    //
    //                MSP430FR2676
    //             -----------------
    //         /|\|                 |
    //          | |                 |
    //          --|RST              |
    //            |                 |
    //            |                 |
    //            |     P5.2/UCA0TXD|----> PC (echo)
    //            |     P5.1/UCA0RXD|<---- PC
    //            |                 |
    //
    //   Longyu Fang
    //   Texas Instruments Inc.
    //   August 2018
    //   Built with IAR Embedded Workbench v7.12.1 & Code Composer Studio v8.1.0
    //******************************************************************************
    #include <msp430.h>
    
    void Init_GPIO();
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop watchdog timer
    
      // Configure GPIO
      Init_GPIO();
    
      PM5CTL0 &= ~LOCKLPM5;                     // Disable the GPIO power-on default high-impedance mode
                                                // to activate 1previously configured port settings
    
      // Configure UART pins
     // SYSCFG3|=USCIA0RMP;                       //Set the remapping source
      P1SEL0 |= BIT4 | BIT5;                    // set 2-UART pin as second function
    
      // Configure UART
      UCA0CTLW0 |= UCSWRST;
      UCA0CTLW0 |= UCSSEL_1;                    // set ACLK as BRCLK
    
      // Baud Rate calculation. Referred to UG 17.3.10
      // (1) N=32768/4800=6.827
      // (2) OS16=0, UCBRx=INT(N)=6
      // (4) Fractional portion = 0.827. Refered to UG Table 17-4, UCBRSx=0xEE.
      UCA0BR0 = 6;                              // INT(32768/4800)
      UCA0BR1 = 0x00;
      UCA0MCTLW = 0xEE00;
    
      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=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_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));
          UCA0TXBUF = UCA0RXBUF;
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
        default: break;
      }
    }
    
    void Init_GPIO()
    {
        P1DIR = 0xFF; P2DIR = 0xFF;
        P1REN = 0xFF; P2REN = 0xFF;
        P1OUT = 0x00; P2OUT = 0x00;
    }