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.

msp430fr5739串口怎么设置

Other Parts Discussed in Thread: MSP430FR5739, MSPWARE

下面是我的串口程序,不知道哪里设置不对,调试不出来,用的是TI的pad,没有外接晶振
#include "msp430fr5739.h"
#define delayus(n) __delay_cycles(n)

void Uart_Init(void)
{
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1); // P2.0,1 = USART0 TXD/RXD 选择端口用作接收和发送端口
UCA0CTL1 |= UCSWRST;
UCA0CTL1 = UCSSEL_2; // Set SMCLK as UCLk
UCA0BR0 = 52 ; // 9600 baud
// 8000000/(9600*16) - INT(8000000/(9600*16))=0.083
UCA0BR1 = 0;
// UCBRFx = 1, UCBRSx = 0x49, UCOS16 = 1 (Refer User Guide)
//UCA0MCTLW = 0x4911 ;
UCA0MCTLW = 0x0411 ;
UCA0CTL1 &= ~UCSWRST; // release from reset
UCA0IE |= UCRXIE; // 使能 USART0 RX 中断

}
void Uart_Put_Char(unsigned char c)
{
while (!(UCA0IFG&UCTXIFG)); //等待发送寄存器为空
UCA0TXBUF = c;
}

void Uart_Put_string(unsigned char *ptr)
{
while(*ptr != '\0')
{
Uart_Put_Char(*ptr++); // 发送数据
}


}

void main(void)
{
CSCTL0_H = 0xA5;
CSCTL1 |= DCORSEL + DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
CSCTL2 = SELA_1 + SELS_3 + SELM_3; // set ACLK - VLO, the rest = MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; // set all dividers to 0
Uart_Init();
while(1)
{
Uart_Put_string( "Sf");
delayus(5000000);
delayus(5000000);
delayus(5000000);
}
}

  • 中断那句是注释掉的

  • UART的设置没有问题,你程序里面既没有关WDT,又没有清WDT的代码。可能是因为看门狗造成的。

  • 您好,请问串口发送不需要请标志?void Uart_Put_Char(unsigned char c)
    {
    while (!(UCA0IFG&UCTXIFG)); //等待发送寄存器为空 
    UCA0TXBUF = c; 

    UCA0IFG&=~UCTXIFG;    //这句可以不写?
    }

  • 最好要清一下的,TXBUF空了之后就会有这个Flag,确保下一次和每一次发的时候TXBUF都真的是空的。

  • 我清了标志会一直循坏在while((UCA1IFG&UCTXIFG)==0);导致程序无法运行。

  • 你好,

    可以用示波器测试,TX有数据输出吗?

    下面是MSP430WARE软件包里面的例程供你参考

    C:\ti\msp430\MSPWare_3_20_00_37\examples\devices\MSP430FR57xx\MSP430FR57xx_Code_Examples\C

    /* --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--*/
    //******************************************************************************
    // MSP430FR57xx Demo - USCI_A0 UART echo at 9600 baud
    //
    // Description: This demo echoes back characters received via a PC serial portt.
    // 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.
    // ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1MHz
    //
    //
    // MSP430FR5739
    //
    // -----------------
    // RST -| P2.0/UCA0TXD|----> PC (echo)
    // | |
    // -| |
    // | P2.1/UCA0RXD|<---- PC
    // | |
    //
    // P. Thanigai
    // Texas Instruments Inc.
    // August 2010
    // Built with CCS V4 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************
    #include <msp430.h>

    unsigned int i;
    unsigned char RXData = 0;
    unsigned char TXData = 0;
    unsigned char check = 0;
    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // stop watchdog

    // XT1 Setup

    PJSEL0 |= BIT4 + BIT5;

    CSCTL0_H = 0xA5;
    CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
    CSCTL2 = SELA_0 + SELS_3 + SELM_3; // set ACLK = XT1; MCLK = DCO
    CSCTL3 = DIVA_0 + DIVS_3 + DIVM_3; // set all dividers
    CSCTL4 |= XT1DRIVE_0;
    CSCTL4 &= ~XT1OFF;

    do
    {
    CSCTL5 &= ~XT1OFFG;
    // Clear XT1 fault flag
    SFRIFG1 &= ~OFIFG;
    }while (SFRIFG1&OFIFG); // Test oscillator fault flag

    // Configure UART pins
    P2SEL1 |= BIT0 + BIT1;
    P2SEL0 &= ~(BIT0 + BIT1);
    // Configure UART 0
    UCA0CTL1 |= UCSWRST;
    UCA0CTL1 = UCSSEL_1; // Set ACLK = 32768 as UCBRCLK
    UCA0BR0 = 3; // 9600 baud
    UCA0BR1 = 0;
    UCA0MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
    // UCBRSx value = 0x53 (See UG)
    UCA0CTL1 &= ~UCSWRST; // release from reset
    UCA0IE |= UCRXIE; // Enable RX interrupt

    __bis_SR_register(LPM0_bits + GIE); // LPM3 + Enable interrupt
    }


    // Echo back RXed character, confirm TX buffer is ready first
    #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,0x08))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
    break;
    case 4:break; // Vector 4 - TXIFG
    default: break;
    }
    }

  • 循坏卡死的时间不一定,有时候过了10来分钟才被卡死,有时候几分钟才被卡死

  • 你一开始的代码是while (!(UCA0IFG&UCTXIFG)); //等待发送寄存器为空 ,这里“!”符号怎么没了?

  • 楼上的眼睛好犀利,赞

  • while (!(UCA0IFG&UCTXIFG))等同于while ((UCA0IFG&UCTXIFG)==0)呀,所以我的问题还是被卡在这里,等待

  • UCA0CTL1 与UCA0CTLW0有什么特别不同?