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.

5510 通用IO口模拟串口通信

现在采用5510的P4.6脚作为输出UART TXD,通过定时器来发送字节,现在默认的晶振12MHz,通过TA1CCR1比较器来做定时间隔发送字节。

配置函数

void IO_Uart_Init (void)
{
 //IO configuration
        TA1CTL  = TASSEL_1 + MC_2 +TACLR;             // SMCLK, continuous mode
        P4SEL  |= TXD + RXD;         // P4.6/7 TA0 for TXD/RXD function
        P4DIR  |= TXD;          // TXD output on P4.6
}

 

发送函数

// Function Transmits Character from RXTXData Buffer
void TX_Byte(U8 data)
{

    __enable_interrupt();               //Enable interrupts globally
    RXTXData=data;
    BitCnt = 0xA;                       // Load Bit counter, 8data + ST/SP
    TA1CCR1 = TA1R;                     // Current state of TA counter
    TA1CCR1 += Bitime;                  // Some time till first bit
    RXTXData |= 0x100;                  // Add mark stop bit to RXTXData
    RXTXData = RXTXData<< 1;            // Add space start bit
    TA1CCTL1 |= CCIE;                   // TXD = mark = idle
    while ( TA1CCTL1 & CCIE );          // Wait for TX completion
}

 

定时中断

// Timer A1 interrupt service routine
#pragma vector=TIMER1_A1_VECTOR
__interrupt void Timer1_A3(void)
{
 TA1CCR1 += Bitime;                            // Add Offset to CC1R1
 if ( BitCnt == 0)
   TA1CCTL1 &= ~ CCIE;                               // All bits TXed, disable interrupt
 else
 {
   if (RXTXData & 0x01)
      P4OUT |= TXD;
   else
      P4OUT &=~TXD;
  
   RXTXData = RXTXData >> 1;
   BitCnt --;
 }
}

如果是12M的频率,波特率为19200,那么12000000/19200=625, 即每隔625ns发送一个bit,但是我串口终端没有接受到任何信息,请问这种方式有问题么?