MSP430FR6972的串口波特率设置代码

1. 本次使用ACLK,就是辅助时钟(32.768KHZ)作为串口的时钟源,那么使用波特率9600的时候,分频系数=32768/9600=3.41,所以是有小数位的,设置代码如下

  UCA0CTLW0 |= UCSWRST;
  UCA0CTLW0 |= UCSSEL__ACLK;                  // Set ACLK = 32768 as UCBRCLK
  UCA0BR0 = 3;
  UCA0MCTLW |= 0x5300;                      // 32768/9600 - 
  UCA0BR1 = 0;
  UCA0CTL1 &= ~UCSWRST;                     // release from reset

根据TI芯片数据手册提供的资料,小数位是0.41的时候查找最接近的值0.4286,那么UCA0MCTLW |= 0x5300;

同理,如果是4800波特率的话,32768/4800=6.82,提取小数位0.82,最接近的值0XBF,那么代码如下

  UCA0CTLW0 |= UCSWRST;
  UCA0CTLW0 |= UCSSEL__ACLK;                  // Set ACLK = 32768 as UCBRCLK
  UCA0BR0 = 6;
  UCA0MCTLW |= 0xbf00;  
  UCA0BR1 = 0;
  UCA0CTL1 &= ~UCSWRST;                     // release from reset
  UCA0IE |= UCRXIE;

 

posted @ 2019-03-18 16:35  429512065  阅读(1186)  评论(0编辑  收藏  举报