打印
[MCU]

【求助】串口通信

[复制链接]
395|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
两只袜子|  楼主 | 2020-11-10 14:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//******************************************************************************
// MSP-FET430P140 Demo - USART0 UART 115200 Echo ISR, HF XTAL ACLK
//
// Description; Echo a received character, RX ISR used. Normal mode is LPM0,
// USART0 RX interrupt triggers TX Echo.
// ACLK = MCLK = UCLK0 = LFXT1 = 8MHz
// Baud rate divider with 8Mhz XTAL = 8000000/115200 = 0069 (0045h)
// //*USART0 interrupt flags are in different SFR's from other MSP430's//
// //*An external 8Mhz XTAL on XIN XOUT is required for ACLK*//
//
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | | 8MHz
// --|RST XOUT|-
// | |
// | P3.4|------------>
// | | 115200 - 8N1
// | P3.5|<------------
//
//
// M. Buccini
// Texas Instruments, Inc
// February 2002
// Built with IAR Embedded Workbench Version: 1.25A
//******************************************************************************

#include <msp430x14x.h>

void main(void)
{
unsigned int i,j,k;
char Data[6]="MSP430";

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL

do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (k = 0xFF; k > 0; k--); // Time for flag to set
}
while ((IFG1 & OFIFG) ==OFIFG); // OSCFault flag still set?

BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe)
UCTL0 = CHAR; // 8-bit character
UTCTL0 = SSEL0; // UCLK = ACLK
UBR00 = 0x45; // 8MHz 115200
UBR10 = 0x00; // 8MHz 115200
UMCTL0 = 0x00; // 8MHz 115200 modulation
ME1 |= UTXE0 + URXE0; // Ena××e USART0 TXD/RXD
// IE1 |= URXIE0; // Ena××e USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction
// _EINT(); // Ena××e interrupts
while(1)
{
TXBUF0=0xFF;
while((UTCTL0&0x01)==0);
for(j=0;j<=6;j++)
{
TXBUF0=Data[j];
P1DIR |=0x02;
P1OUT ^=0x02;
i=50000;
do(i--);
while(i!=0);
while((UTCTL0&0x01)==0);
}
}

for (;;)
{
_BIS_SR(CPUOFF); // Enter LPM0
_NOP(); // Required only for C-spy
}
}

interrupt[UART0RX_VECTOR] void usart0_rx (void)
{
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}

运行该例程 执行到while ((IFG1 & OFIFG) ==OFIFG); // OSCFault flag still set?
就运行不下去了!在此反复循环!不知道是何原因!请各位大侠指导!

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2055

主题

7458

帖子

10

粉丝