TI中文支持网
TI专业的中文技术问题咨询交流网站

MSP430F4152串口调试问题

请教大神,在用MSP430F4152做串口调试时,程序是讲接受的数据再发送出来,可是使用串口调试助手发送与接受的数据不同,必须在发送数据前加00,可即便如此接收的数据会后面多出00;还有一个问题就是发送的数据不能太大,数据大就会出现问题,程序如下:

#include  <msp430x41x2.h>

int main(void)
{
volatile unsigned int i;
/* HAL clock init */
HW_MCLK_INIT();
for ( i = 0; i < 10000; i++); // Delay for 32 kHz crystal to stabilize
do {
IFG1 &= ~OFIFG; // Clear osc fault flag
for (i = 0; i < 1000; i++); // Delay for osc to stabilize
} while(IFG1 & OFIFG); // Check to see if osc flag is set

HW_UART_INIT();
IE2 |= UCA0RXIE; _BIS_SR(LPM3_bits + GIE); // Enter LPM0, interrupts enabled
// _EINT(); /* enable all interrupt */
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
{
while(!(IFG2&UCA0TXIFG)); UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}

///////////////////////////////////////////////////////////////////////////////////////////////////

void HW_MCLK_INIT() \
{ \
WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */ \
_DINT(); /* disable all interrupt */ \
SCFI0 |= FN_2; /* x2 DCO freq, 8MHz nominal DCO */ \
SCFQCTL = 121; /* (121+1) x 32768 x 2 = 7.99 Mhz */ \
FLL_CTL0 |= DCOPLUS + XCAP5_5F; /* DCO+ set so freq= xtal x D x N+1 */ \
}

/////////////////////////////////////////////////////////////////////////////////////////////
/* ——— Board HAL UART Initialization ——– */
void HW_UART_INIT() \
{ \
UCA0CTL1 |= UCSWRST; \
P6SEL |= (BIT5 + BIT6); /* P6.5,6 = USCI_A0 RXD TXD */ \
P6DIR |= BIT6; /* P6.6 Tx */ \
P6DIR &= ~(BIT5); /* P6.5 Rx */ \
UCA0CTL0 = 0; /* no parity, 8bit, 1stop, lSb first,uart */ \
UCA0CTL1 |= UCSSEL_2; /* BRCLK=SMCLK = 8MHz */ \
UCA0BR0 = 52; /* 8MHz/9600 = ~833.3 = 0x0341 */ \
UCA0BR1 = 0; \
UCA0MCTL = UCOS16; /* Modulation UCBRSx = 2 */ \
UCA0CTL1 &= ~UCSWRST; /* Initialize USCI state machine */ \
}

串口调试助手发送接收数据如下图:

Seven Han:

在用MSP430F4152做串口调试时,程序是讲接受的数据再发送出来,可是使用串口调试助手发送与接受的数据不同,必须在发送数据前加00,可即便如此接收的数据会后面多出00;还有一个问题就是发送的数据不能太大,数据大就会出现问题,

您检查下波特率以及校验位设置是否有问题?

Isaiha:

回复 Seven Han:

现在设置是禁止校验的,波特率也计算试过了,还是存在同样的问题

gaoyang9992006:

/* --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--*/
//******************************************************************************
//MSP430F41x2 Demo - USCI_A0, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
//Description: Echo a received character, RX ISR used. Normal mode is LPM3,
//USCI_A0 RX interrupt triggers TX Echo.
//ACLK = BRCLK = LFXT1 = 32768, MCLK = SMCLK = DCO~1048k
//Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 03h)
////* An external watch crystal is required on XIN XOUT for ACLK *////
//
//MSP430F41x2
//-----------------
///|\|XIN|-
//| || 32kHz
//--|RSTXOUT|-
//||
//|P6.5/UCA0RXD|------------>
//|| 9600 - 8N1
//|P6.6/UCA0TXD|<------------
//
//P. Thanigai
//Texas Instruments Inc.
//January 2009
//Built with CCE Version: 3.1 and IAR Embedded Workbench Version: 4.11
//******************************************************************************#include <msp430.h>int main(void)
{volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD;// Stop WDTFLL_CTL0 |= XCAP11PF;// Configure load capsdo{IFG1 &= ~OFIFG;// Clear OSCFault flagfor (i = 0x47FF; i > 0; i--);// Time for flag to set}while ((IFG1 & OFIFG));// OSCFault flag still set?P6SEL |= BIT5+BIT6;// P6.5,6 = USCI_A0 RXD/TXDUCA0CTL1 |= UCSSEL_1;// CLK = ACLKUCA0BR0 = 0x03;// 32k/9600 - 3.41UCA0BR1 = 0x00;//UCA0MCTL = 0x06;// ModulationUCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**IE2 |= UCA0RXIE;// Enable USCI_A0 RX interrupt__bis_SR_register(LPM3_bits + GIE);// Enter LPM0, interrupts enabled
}//Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIA0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{while(!(IFG2&UCA0TXIFG));UCA0TXBUF = UCA0RXBUF;// TX -> RXed character
}

官方的一个例子。

Isaiha:

回复 gaoyang9992006:

发送接收数据不能大于127,如果大于127就会出错,之后发送的所有数据都会出错,这是为什么?请求指点,谢谢!

赞(0)
未经允许不得转载:TI中文支持网 » MSP430F4152串口调试问题
分享到: 更多 (0)