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.

MSP430F4250模拟串口



使用F4250模拟串口使用TI提供的例程如下

#include  <msp430x42x0.h>

#define RXD   0x02                          // RXD on P1.1
#define TXD   0x01                          // TXD on P1.0

//  Conditions for 2400 Baud SW UART, ACLK = 32768

#define Bitime_5  0x06                 // ~ 0.5 bit length + small adjustment
#define Bitime    0x0E                 // 427us bit lengtjh ~ 2341 baud

unsigned int RXTXData;
unsigned char BitCnt;

void TX_Byte(void);
void RX_Ready(void);

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  FLL_CTL0 |= XCAP14PF;                     // Configure load caps
  CCTL0 = OUT;                              // TXD Idle as Mark
  TACTL = TASSEL_1 + MC_2;                  // ACLK, continous mode
  P1SEL = TXD + RXD;                        // P1.0/1 TA0 for TXD/RXD function
  P1DIR = TXD;                              // TXD output on P1

  // Mainloop
  for (;;)
  {
    RX_Ready();                             // UART ready to RX one Byte
    _BIS_SR(LPM3_bits + GIE);               // Enter LPM3 Until character RXed
    TX_Byte();                              // TX Back RXed Byte Received
  }
}


// Function Transmits Character from RXTXData Buffer
void TX_Byte(void)
{
  BitCnt = 0xA;                             // Load Bit counter, 8data + ST/SP
  CCR0 = TAR;                               // Current state of TA counter
  CCR0 += Bitime;                           // Some time till first bit
  RXTXData |= 0x100;                        // Add mark stop bit to RXTXData
  RXTXData = RXTXData << 1;                 // Add space start bit
  CCTL0 = OUTMOD0 + CCIE;                   // TXD = mark = idle
  while ( CCTL0 & CCIE );                   // Wait for TX completion
}


// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready(void)
{
  BitCnt = 0x8;                             // Load Bit counter
  CCTL0 = SCS + CCIS0 + OUTMOD0 + CM1 + CAP + CCIE;  // Sync, Neg Edge, Capture
}


// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
  CCR0 += Bitime;                           // Add Offset to CCR0

  // RX
  if (CCTL0 & CCIS0)                        // RX on CCI0B?
  {
    if( CCTL0 & CAP )                       // Capture mode = start bit edge
    {
      CCTL0 &= ~ CAP;                       // Capture to compare mode
      CCR0 += Bitime_5;
    }
    else
    {
      RXTXData = RXTXData >> 1;
      if (CCTL0 & SCCI)                     // Get bit waiting in receive latch
        RXTXData |= 0x80;
      BitCnt --;                            // All bits RXed?
      if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      {
        CCTL0 &= ~ CCIE;                    // All bits RXed, disable interrupt
        _BIC_SR_IRQ(LPM3_bits);             // Clear LPM3 bits from 0(SR)
      }
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    }
  }
  // TX
  else
  {
    if ( BitCnt == 0)
      CCTL0 &= ~ CCIE;                      // All bits TXed, disable interrupt
    else
    {
      CCTL0 |=  OUTMOD2;                    // TX Space
      if (RXTXData & 0x01)
        CCTL0 &= ~ OUTMOD2;                 // TX Mark
      RXTXData = RXTXData >> 1;
      BitCnt --;
    }
  }
}

经测试无法正常的完成串口收发,F4250不断的给PC发送FF,F4250软串口接收没反应

问题出在哪里?我该怎么检测?

  • 来自TI官网的例程程序,都是经过验证的。请检查一下你的外部电路是否正确

  • 这个例程应该是从PC串口接收一个字符,然后再从MCU的串口发出来到PC,你现在“4250不断的给PC发送FF,F4250软串口接收没反应”,完全和程序的执行不一致。

    建议首先检查32768有没有起振,然后再跟踪调试程序,看程序是否正常执行。

  • 1.TI提供的例程都是经过了测试的,如果硬件工作正常是可以正常运行的

    2.要检查你出现的问题,可以把PC机与MCU断开,发送数据时用示波器看有没有需要的串口数据波形(包括频率和数据)

  • 您好,我想问下msp430中IO口模拟串口是任何IO口都能去模拟了?还是要一些固定的IO口才能模拟,比如f5529单片机中P7.4和P7.5能否模拟串口了?希望能得到您的回复

  • 可以的。P7.4和P7.5默认就是普通io,和其他io一样

  • 是要有TA第二功能的IO口才行吧,没有第二功能怎么捕获比较呢?

  • 我现在正调试模拟串口,有点小经验,不知对不对,你可以试一下。

    1、我也遇到过一直往外发FF的情况,是在我尝试去掉低功耗的时候,毕竟我们在实际用的时候不可能用睡眠的方式等待串口收数据。一去掉LPM,就会一直往外发数。PS:现在我还没想到用到实际中的方法,先准备接,再收数据,实际中哪有这么好的情况!(有,但更想要的是,不定时接收)

    2、串口波特率与上位机调试助手不一致,有可能收到乱码。可以有示波器打一下,看看。我现在一直在波特率出问题的地方打转,还没有解决。楼主要是有相关经验,希望能给我解下惑!http://www.deyisupport.com/question_answer/microcontrollers/msp430/f/55/p/98947/259157.aspx#259157