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.

请教一个串口的奇怪问题

Other Parts Discussed in Thread: MSP430F2252

先说说我的开发环境:

IAR + 430LaunchPad + msp430F2252目标板。

电路上断开launchpad的J3跳线(VCC保留),连接到目标板上,可以调试,仿真和串口。

问题来了,我写了一段双工的串口程序,结果:可以收到PC端的,却不能发送到PC,怪异的是示波器查看TXD有输出,9600波特率每位约103.5us,应该算标准了,但PC就是收不到,换了几个软件都不行。

我又用launchpad带的G2553试了模拟串口的程序,收发都可以,所以硬件应该没问题

下面把程序贴出来,大家帮我检查一下那里配置错了。其实程序参考例程的。

#include "io430.h"
#include "led.h"

#define UCA0_TXD BIT4
#define UCA0_RXD BIT5

char string1[8]="u hello";
char i;
char j = 0;

void uart_init(void)
{

P3SEL = UCA0_TXD + UCA0_RXD; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // CLK = ACLK
UCA0BR0 = 0x68; // 1.MHz/9600 = 125
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS2; // Modulation UCBRSx = 0x04
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt


}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
UCA0TXBUF = string1[i++]; // TX next character
//LED_PWR_GRN_BLINK;
if (i == sizeof string1 - 1) // TX over?
{
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt

i=0;
}
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if (UCA0RXBUF == 'u') // 'u' received?
{
i = 0;
UCA0TXBUF = string1[i++];
//LED_GAME_RED_BLINK;
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
}
}

我时钟选得smclk = dco =1MHZ

主函数调用

uart_init();
__bis_SR_register(GIE); // interrupts enabled
while(1);

请各位指点下。

  • 楼主你好!

    试一下超级终端,参考附件

    Hypertrm.7z
  • 试过了,一样不行。我用timer模拟的uart可以工作,所以估计是程序问题

  • /* --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--*/
    //******************************************************************************
    // MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK
    //
    // Description: Echo a received character, RX ISR used. Normal mode is LPM0.
    // USCI_A0 RX interrupt triggers TX Echo.
    // Baud rate divider with 1MHz = 1MHz/9600 = ~104.2
    // ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
    //
    // MSP430G2xx3
    // -----------------
    // /|\| XIN|-
    // | | |
    // --|RST XOUT|-
    // | |
    // | P1.2/UCA0TXD|------------>
    // | | 9600 - 8N1
    // | P1.1/UCA0RXD|<------------
    //
    // D. Dang
    // Texas Instruments Inc.
    // February 2011
    // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************
    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    if (CALBC1_1MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;
    P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
    P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 104; // 1MHz 9600
    UCA0BR1 = 0; // 1MHz 9600
    UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

    __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
    }

    // Echo back RXed character, confirm TX buffer is ready first
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
    while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
    }

  • 谢谢你的回复。

    我用一块单独的usb转串口的板子接到目标板上通讯成功,你提供的和我以前的均能正常工作。

    可能是launchpad串口的问题,我不知道有人在上面试过硬件串口收发送没有?

  • 有一个版本的launch pad硬件布线有问题,楼主需要检查下跳线连接。

  • 你看你的lanuchpad是1.4的还是1.5的版本。1.4的uart的tx跟rx引脚接反了,需要自己跳线校正。

  • 我的是V1.4的板子,请问引脚标记错误的问题有相关说明吗,另外我接收PC的字符是正确的哦。奇怪

  • 楼主,有一版本LaunchPad的串口引脚更改了,所以仔细看一下你那个版本的原理图;

    然后用示波器仔细看看波形情况。

    谢谢。