其他分享
首页 > 其他分享> > MSP430FR6972的串口波特率设置代码

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;

 

标签:32768,UCA0CTLW0,小数位,ACLK,MSP430FR6972,串口,波特率,UCSWRST
来源: https://www.cnblogs.com/429512065qhq/p/10552966.html