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.

msp430i2021 串口波特率不稳

Other Parts Discussed in Thread: MSP430I2021

这两天在开发msp430i2021的串口驱动,串口一直发送都是乱码。然后按照ti的例程测试了串口的波特率,发现很不稳定。下面是测试代码

#include "msp430.h"
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1SEL0 |= BIT2 | BIT3; // P1.2/3 eUSCI_A Function
P1SEL1 &= ~(BIT2 | BIT3);

UCA0CTL1 |= UCSWRST; // Hold eUSCI in reset
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 142; // 115200 baud
UCA0BR1 = 0;
UCA0MCTLW = 0x2200; // 16.384MHz/115200 = 142.22 (See UG)
UCA0CTL1 &= ~UCSWRST; // Release from reset
// UCA0IE |= UCRXIE; // Enable RX interrupt

// __bis_SR_register(LPM0_bits | GIE); // Enter LPM0
__no_operation(); // For debugger

while(1)
{
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0xaa; // TX -> RXed character
//__delay_cycles(90000000);
}
}

正常的115200测试的脉冲宽度应该是8.6us,现在测到是6.8~13us,这个差太多了,望大家不吝赐教啊

  • 请问您是否有用TI的例程测试过?有没有尝试修改波特率?
  • 这个就是ti的例程测试的结果

  • do
    {
    checksum ^= *TLV_address_for_checksum++;
    } while (TLV_address_for_checksum <= (unsigned int *)TLV_END);

    checksum ^= 0xFFFF;
    checksum++;

    /* If check sum is not correct go to LPM4 */
    if (*((unsigned int *)TLV_START) != checksum)
    {
    /* Enter LPM4 if checksum failed */
    __bis_SR_register(LPM4_bits);
    }

    调用low_lwvel_init.c后,程序进入了lpm4,这问题怎么解决?

  • 如果不想进入lpm4,把__bis_SR_register(LPM4_bits);这句代码注释掉就可以

  • 校验值的计算方法如下

    #include "msp430i2021.h"
    #pragma location=0x10C0
    __no_init unsigned int infoA[32];
    void main(void)
    {
      unsigned chksum = 0;
      for (int i = 1; i < 32; i++)
        chksum ^= infoA[i];
      if ((chksum + infoA[0]) == 0)
        { /* chksum correct */ }
      else
        { /* chksum incorrect */ }
    }

    当SegA内的值被修改时就有可能出现这个错误