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-EXP430FR5969:UART 配置

Guru**** 2779745 points

Other Parts Discussed in Thread: MSP430FR5969

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1612232/msp-exp430fr5969-uart-configuration

器件型号: MSP-EXP430FR5969
Thread 中讨论的其他器件: MSP430FR5969MSP430WARE

尊敬的团队:

我是 MSP430FR5969 Lanchpad 开发套件、
我正在构建一个应用、 P2.5(引脚 20)和 P2.6(引脚 21)应充当 UART (UCA1TXD、UCA1RXD)、它应能够从主机 PC 发送和接收数据、但使用 MSP430Ware SDK、P2.0/UCA0TXD 和 P2.1/UCA0RXD UART 仅支持应用、如何为 UCA1 配置 UART。

此致、
Nikhil K

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

    您可以显示您的代码、但通常它与将所有“0"更“更改为“1"一样“一样简单。 在名称中。

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

    尊敬的 Keith:

    我也在 TXD 和 RXD(20 引脚 BoosterPack 插件模块)上连接了 3V3 TTL 电缆。 但在调试终端上看不到任何内容、无法提供任何输入

    您是否有这方面的任何参考应用

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, 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--*/
    //******************************************************************************
    //  MSP430FR59xx Demo - eUSCI_A0 UART echo at 9600 baud using BRCLK = 8MHz
    //
    //  Description: This demo echoes back characters received via a PC serial port.
    //  SMCLK/ DCO is used as a clock source and the device is put in LPM3
    //  The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
    //  when the UART is idle and turned on when a receive edge is detected.
    //  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 = VLO, MCLK =  DCO = SMCLK = 8MHz
    //
    //                MSP430FR5969
    //             -----------------
    //       RST -|     P2.5/UCA1TXD|----> PC (echo)
    //            |                 |
    //            |                 |
    //            |     P2.6/UCA1RXD|<---- PC
    //            |                 |
    //
    //   P. Thanigai
    //   Texas Instruments Inc.
    //   August 2012
    //   Built with IAR Embedded Workbench V5.40 & Code Composer Studio V5.5
    //******************************************************************************
    #include "msp430.h"
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog
    
      // Configure GPIO
      P2SEL1 |= BIT0 | BIT1;                    // USCI_A1 UART operation
      P2SEL0 &= ~(BIT0 | BIT1);
    
      // 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 >> 8;                    // Unlock clock 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_A1 for UART mode
      UCA1CTLW0 = UCSWRST;                      // Put eUSCI in reset
      UCA1CTLW0 |= 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
      UCA1BR0 = 52;                             // 8000000/16/9600
      UCA1BR1 = 0x00;
      UCA1MCTLW |= UCOS16 | UCBRF_1;
      UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
      UCA1IE |= UCRXIE;                         // Enable USCI_A1 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_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      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;
      }
    }
    

    此致、


    Nikhil K

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

    UART0 通过 J13 短接跳线、通过 2.0/2.1 连接到反向通道 UART。 如果您希望 UART1 连接到 PC/反向通道 UART、则需要移除 TX 和 RX 短接跳线、并从 2.5/2.6 中添加您自己的有线跳线。

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

    如果我想通过 UART 从 MSP 发送一些数据到主机 PC、如何输入数据(CCS 中是否会显示 MSP 的任何调试提示/终端)?
    如果我在 MSP 应用程序上添加一些调试打印 (printf)、因为我在 CCS 的调试控制台、调试输出或输出窗口上看不到任何打印。

    此致、

    Nikhil K

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

    您好、Nikhil、

    如果要使用 MSP430 通过 UART 发送数据到 PC、则需要在代码中编写相关代码。 例如、如下所示:

    while(!(UCA0IFG & UCTXIFG));

    UCA1TXBUF = xxx(您要发送);

    或者在调试模式下、打开“register"窗口“窗口、并将数据直接写入 TX 寄存器  

    关于“printf",“,实际上、实际上“printf"也“也需要串行端口(通常是 UART)、因此您在 CCS 窗口中看不到它。 您可以查看“printf"函“函数的定义。

    此致、  

    Janz Bai

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

    关于“printf",“,实际上、实际上“printf"也“也需要串行端口(通常是 UART)、因此您在 CCS 窗口中看不到它。 您可以转到“printf"函“函数的定义。“

    我不认为这是完全正确的。 printf() 使用通过 JTAG 与 MCU 通信的*other* UART 端口。 它根本不涉及 MCU UART。 基本上、printf 会创建一个通过 JTAG 传输到主机的存储器缓冲区、而 CCS/THEIA 中的调试软件通常会以缓慢且随机的方式将其打印到控制台。

    所以,操作,你可以使用 printf,但你*不能*使用它将数据发送到像 PuTTY 这样的终端程序,除非你做一些野生的 gyatrations 来重新定向 stdout ,这是我从未理解的。 (您应该在每次 printf 之后执行 fflush (stdout))

    基本 MSP430 没有终端软件、因此无法  “输入数据(CCS 中是否会显示 MSP 的任何调试提示/终端)“。

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

    明白了、  

    对于 UART 时钟配置、 eusci_a_uart_ex1_loopbackAdvanced.c 文件中提供的示例仅显示了从外部晶体配置基准时钟  
      *选择端口 J
      *将引脚 4、5 设置为输入主模块功能、LFXT。
      */
      GPIO_setAsPeripheralModuleFunctionInputPin (
        GPIO_PORT_PJ、
        GPIO_PIN4 + GPIO_PIN5、
        GPIO_PRIMARY_MODULE_FUNCTION
      );

      //将 DCO 频率设置为 1MHz
      CS_setDCOFreq (CS_DCORSEL_0、CS_MDCOFSEL_0);
      //将外部时钟频率设置为 32.768KHz
      CS_setExternalClockSource (32768、0);
      //将 ACLK 设置为 LFXT
      CS_initClockSignal (CS_ACLK、CS_LFXTCLK_SELECT、CS_clock_divider_1);
      //将 SMCLK 设置为 DCO、分频器为 1
      CS_initClockSignal (CS_SMCLK、CS_DCOCLK_SELECT、CS_clock_divider_1);
      //将 MCLK 设置为 DCO、分频器为 1
      CS_initClockSignal (CS_MCLK、CS_DCOCLK_SELECT、CS_clock_divider_1);
      //在没有超时的情况下启动 XT1
      CS_TURNOnLFXT (CS_LFXT_DRIVE_0);


      //配置 UART 引脚
      //将 P2.0 和 P2.1 设置为辅助模块功能输入。
      /*

      *选择端口 2D
      *设置引脚 0、1 以输入辅助模块功能 (UCA0TXD/UCA0SIMO、UCA0RXD/UCA0SOMI)。
      */
      GPIO_setAsPeripheralModuleFunctionInputPin (
      GPIO_PORT_P2、
      GPIO_PIN0 + GPIO_PIN1、
      GPIO_SECONDARY_MODULE_FUNCTION
      );

    您能否提供一些参考实现来为 UCA1 UART 配置来自内部时钟发生器的时钟  
    似乎“msp430fr59xx_euscia0_uart_01.c"此“此文件会为 UART 实现内部时钟、但在本例中、一切都是寄存器读取/写入。 您能否提供 eusci_a_uart_ex1_loopbackAdvanced.c 中所述 API 调用/driverlib 函数的实现示例  

    此致、
    Nikhil K

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

    我建议您使用一个示例中的时钟代码并将其添加到您的工作串行示例中。