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

MSP430F1232串口通信问题

Hi,Everyone:

我有个问题,在使用MSP430F1232的时候遇到串口通信失败,无法接收到数据的情况,板子参考TI官方的Launchpad。

代码如下:

//  MSP-FET430P120 Demo - USART0, UART 9600 Echo ISR, 32kHz ACLK + DCO
//
//  Description: Echo a received character, USART0 RX ISR at high-speed using
//  32kHz XTAL and DCO. Normal operation in LMP0, DCO continuously stabilized,
//  interrupt driven using CCR2. DCO used for UART baud generation. On a valid
//  RX character, character is echoed back.
//  Baud rate divider with 2MHz = 2MHz/9600 ~ 208 (00D0h)
//  ACLK = LFXT1/8 = 32768/8, MCLK = SMCLK = UCLK0 = DCOCLK  ~2MHz
//  //* An external 32kHz watch crystal on XIN XOUT is required for ACLK *//
//MSP430F123(2)
//-----------------
///|\|XIN|-
//| || 32768Hz
//--|RSTXOUT|-
//||
//|P3.4|------------>
//|| 9600 - 8N1
//|P3.5|<------------


#include <msp430.h>
#define DELTA 488// target DCO = DELTA*(4096) ~2MHz

void delayms(int t)
{int i;while(t--)for(i=150;i>0;i--);//delay ms
}

unsigned int Compare, Oldcapture;

int main(void)
{WDTCTL = WDTPW + WDTHOLD;// Stop WDTP1SEL=0;// SET P1 AS IOP1DIR=0xFF;//SET P1 DIR OUTP1OUT=0xFF;//P1 OUT VALUEP3SEL |= 0x30;// P3.4,5 = USART0 TXD/RXDBCSCTL1 |= DIVA_3;// ACLK = LFXT1CLK/8ME2 |= UTXE0 + URXE0;// Enabled USART0 TXD/RXDUCTL0 |= CHAR;// 8-bit characterUTCTL0 |= SSEL1;// UCLK = SMCLKUBR00 = 0xD0;// 2MHz 9600UBR10 = 0x00;//UMCTL0 = 0x00;// no modulationUCTL0 &= ~SWRST;// Initalize USART state machineIE2 |= URXIE0;// Enabled USART0 RX interruptCCTL2 = CM_1 + CCIS_1 + CAP + CCIE;// CAP, ACLK, interruptTACTL = TASSEL_2 + MC_2 + TACLR;// SMCLK, cont-mode, clear__bis_SR_register(LPM0_bits + GIE);// Enter LPM0 w/ interrupt
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USART0RX_VECTOR))) usart0_rx (void)
#else
#error Compiler not supported!
#endif
{while (!(IFG2 & UTXIFG0));// USART0 TX buffer ready?TXBUF0 = RXBUF0;// RXBUF0 to TXBUF0//while receive the data, led blink and resend data to tx.P1OUT=1;delayms(50);//delayP1OUT=0;delayms(50);//delay
}


// Timer_A3 Interrupt Vector (TAIV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMERA1_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{switch( TAIV ){case  2: break;// CCR1 not usedcase  4:{Compare = CCR2;// Get current captured SMCLKCompare = Compare - Oldcapture;// SMCLK differenceOldcapture = CCR2;// Save current captured SMCLKif (DELTA < Compare){DCOCTL--;if (DCOCTL == 0xFF)// DCO is too fast, slow it down{if (!(BCSCTL1 == (XT2OFF + DIVA_3)))BCSCTL1--;// Did DCO role under?, Sel lower RSEL}}else{DCOCTL++;// DCO is too slow, speed it downif (DCOCTL == 0x00){if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x07)))BCSCTL1++;// Did DCO role over? Sel higher RSEL}}}case 10: break;// not used}
}

但串口依旧无法收发数据,通过示波器测得串口通信工具发送波形如下,请TI专家帮忙分析一下,谢谢!

灰小子:

这个波形很明显有问题啊。建议上传一下电路原理图和pcb图

gaoyang9992006:

如果你跑官方例子都不行,那明显是硬件电路板出问题了 。

Jack Chu:

回复 灰小子:

这个就是支持14 pin JTAG和 BSL下载的最小系统,所有引脚都已经引出来,P3.5 P3.4配置为RXD TXD。

Jack Chu:

回复 gaoyang9992006:

确认硬件没有问题,正常的GPIO操作都没有问题,用的是32768HZ无源晶振

Susan Yang:

回复 Jack Chu:

您现在使用的是TI的官方例程进行测试的?是否有进行CCS连接板子在线调试?

Jack Chu:

回复 Susan Yang:

没有使用CSS在线调试,只将官方给的参考例子稍微修改后编译出txt文件,下载到目标板中。

Susan Yang:

回复 Jack Chu:

建议您在线设置断点调试一下

yongqing wang:

回复 Jack Chu:

通过IAR或者ccs调试,查看串口寄存器的配置是否正常

Jack Chu:

回复 yongqing wang:

我用MAX3232作RXD TXD隔离,串口不停打印0字符,VCC GND不接电源时,串口小助手能够返回发送数据

donghai xu:

回复 yongqing wang:

试用,好产品

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