TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430F247串口通信调试问题

串口调试过程中,在接收函数中设置断点,通过串口调试助手发送但直接响应断点,发送多个字节,只有最后一个字节响应断点,这是什么问题?中断响应不是一帧有多少个字节就响应多少次中断吗?还是我设置的问题。程序的设置如下:

时间设置为内部DCO 8M:

WDTCTL = WDTPW + WDTHOLD; //关闭看门口
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
BCSCTL2 |= SELM_2 + SELS; //MCLK = SMCLK = XT2

串口0初始化:

void initTR0(void) //串口A0为232接口,读取测距机数据{
P3SEL |= 0xF0; // P3.4,5 = USART0 TXD/RXD
UCA0CTL1 |= UCSSEL_2;          //串口时钟选择SMCLK
UCA0BR0 = 0xA0;                      //8M/19200 417 ,地位
UCA0BR1 = 0x01;                      //高位
UCA0MCTL = UCBRS0;             //修正值
UCA0CTL1 &= ~UCSWRST;      //Initialize USART state machine
UC0IE |= UCA0RXIE;                 //开启串口0接收中断
}

串口接收中断响应:

#pragma vector=USCIAB0RX_VECTOR
__interrupt void usart0_rx (void)
{
//while(!(IFG2 & UCA0TXIFG)); //USCI_A0 发送寄存器准备好了?
//UCA0TXBUF = UCA0RXBUF; // 发送寄存器将接收的数据发送出去
if(Flag == 0)
{
if(UCA0RXBUF == 0x44) //判断是帧头读取数据
{
laserData[0] = UCA0RXBUF;
Flag = 1;
m = 1;
}
} else
{
laserData[m] = UCA0RXBUF;
m++;
if(12 == m) {
Flag = 0;
m = 0;
}
}
}

在主程序中开总中断:

_EINT(); //开总中断

Susan Yang:

您可以直接使用TI的例程

/* --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--*/
//******************************************************************************
//MSP430x24x Demo - USCI_A0, 19200 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/19200 = ~52.1
//ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
//MSP430F249
//-----------------
///|\|XIN|-
//| ||
//--|RSTXOUT|-
//||
//|P3.4/UCA0TXD|------------>
//|| 19200 - 8N1
//|P3.5/UCA0RXD|<------------
//
//B. Nisarga
//Texas Instruments Inc.
//September 2007
//Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430.h>int main(void)
{WDTCTL = WDTPW + WDTHOLD;// Stop WDTif (CALBC1_1MHZ==0xFF)// If calibration constant erased{while(1);// do not load, trap CPU!!}DCOCTL = 0;// Select lowest DCOx and MODx settingsBCSCTL1 = CALBC1_1MHZ;// Set DCODCOCTL = CALDCO_1MHZ;P3SEL = 0x30;// P3.4,5 = USCI_A0 TXD/RXDUCA0CTL1 |= UCSSEL_2;// SMCLKUCA0BR0 = 52;// 1MHz 19200UCA0BR1 = 0;// 1MHz 19200UCA0MCTL = UCBRS0;// Modulation UCBRSx = 1UCA0CTL1 &= ~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
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCI0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{while (!(IFG2 & UCA0TXIFG));// USCI_A0 TX buffer ready?UCA0TXBUF = UCA0RXBUF;// TX -> RXed character
}

灰小子:

如果只是用到串口中断,一般是一个字节产生一次中断。

建议楼主先 运行一下例程,看是否正常

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