历史上的今天
今天是:2025年01月10日(星期五)
2021年01月10日 | 单片机 MSP430 串口 计算 波特率
2021-01-10 来源:eefocus
软件计算波特率地址:http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
MSP430怎么计算波特率在各手册都有提到,但始终不清楚,直到看了官网的一篇文章:
https://processors.wiki.ti.com/index.php/USCI_UART_Baud_Rate_Gen_Mode_Selection
The formulas for calculating USCI UART Baud Rate Register Values are basically available in the Family User’s Guide document.
For calculating all the formula, it requires the division factor N:
N = fBRCLK/Baudrate
Where fBRCLK is basically the input clock frequency of the USCI module as shown in the USCI block diagram as follows:

If N >= 16, it is possible to enable the oversampling mode (setting UCOS16=1).
Low Frequency Baud-Rate Mode Setting (UCOS16=0)
In Low Frequency Baud-Rate Mode Setting, the baud rate prescaler register UCBRx and the fractional portion modulator UCBRSx can be calculated as follows:
UCBRx = INT(N) -> integer part of N
*UCBRSx = round((N - INT(N))8) -> integer rounding of fractional part of N times 8
Comparing it to the Baud Rate Setting Register Table provided in the User Guide document tidoc:slau208m Table 34-4. “Commonly Used Baud Rates, Settings, and Errors, UCOS16 = 0”-
For fBRCLK=1MHz, BR=9600: N=1000000/9600 = 104.16666667
UCBRx = INT(N) = 104
UCBRSx = round (0.16666667 * 8) = round (1.33333333) = 1
For fBRCLK=1MHz, BR=19200: N=1000000/19200 = 51,020408163265306122448979591837
UCBRx = INT(N) = 51
UCBRSx = round (0,020408163265306122448979591837 * 8) = round (0,16326530612244897959183673469388) = 0
For fBRCLK=1MHz, BR=38400: N=1000000/38400 = 26,041666666666666666666666666667
UCBRx = INT(N) = 26
UCBRSx = round (0,041666666666666666666666666667 * 8) = round (0,33333333333333333333333333333333) = 0
For fBRCLK=1MHz, BR=57600: N=1000000/57600 = 17,361111111111111111111111111111
UCBRx = INT(N) = 17
UCBRSx = round (0,361111111111111111111111111111 * 8) = round (2,8888888888888888888888888888889) = 3
For fBRCLK=1MHz, BR=115200: N=1000000/115200 = 8,6805555555555555555555555555556
UCBRx = INT(N) = 8
UCBRSx = round (0,6805555555555555555555555555556 * 8) = round (5,4444444444444444444444444444444) = 6
Oversampling Baud-Rate Mode Setting (UCOS16=1)
In Oversampling Mode Setting, the baud rate prescaler register UCBRx and the first stange modulator register UCBRFx can be calculated as follows:
UCBRx = INT(N/16) -> integer part of N divided by 16
*UCBRFx = round(((N/16) - INT(N/16))16) -> integer rounding of fractional part of N divided by 16 times 16
Comparing it to the Baud Rate Setting Register Table provided in the User Guide document tidoc:slau208m Table 34-5. “Commonly Used Baud Rates, Settings, and Errors, UCOS16 = 1”.
For fBRCLK=4MHz, BR=9600: N/16=4000000/9600/16 = 26,041666666666666666666666666667
UCBRx = INT(N/16) = 26
UCBRFx = round (0,041666666666666666666666666667 * 16) = round (0,66666666666666666666666666666667) = 1
For fBRCLK=4MHz, BR=19200: N/16=4000000/19200/16 = 13,020833333333333333333333333333
UCBRx = INT(N/16) = 13
UCBRFx = round (0,020833333333333333333333333333 * 16) = round (0,33333333333333333333333333333333) = 0
For fBRCLK=4MHz, BR=38400: N/16=4000000/38400/16 = 6,5104166666666666666666666666667
UCBRx = INT(N/16) = 6
UCBRFx = round (0,5104166666666666666666666666667 * 16) = round (8,1666666666666666666666666666667) = 8
参考代码:


// MSP430G2xx3
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2/UCA0TXD|------------>
// | | 9600 - 8N1
// | P1.1/UCA0RXD|<------------
#define CPU_F ( (double) 8000000)
#define delay_us( x ) __delay_cycles( (long) (CPU_F * (double) x / 1000000.0) )
#define delay_ms( x ) __delay_cycles( (long) (CPU_F * (double) x / 1000.0) )
/* 串口波特率计算,当BRCLK=CPU_F时用下面的公式可以计算,否则要根据设置加入分频系数 */
#define baud 9600 /* 设置波特率的大小 */
#define baud_setting (uint) ( (ulong) CPU_F / ( (ulong) baud) ) /* 波特率计算公式 */
#define baud_h (uchar) (baud_setting >> 8) /* 提取高位 */
#define baud_l (uchar) (baud_setting) /* 低位 */
void initUSART(void)
{
P1SEL = BIT1 + BIT2; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = baud_l; // 8MHz 9600
UCA0BR1 = baud_h; // 8MHz 9600
UCA0MCTL = UCBRS1; // Modulation UCBRSx 2=010= UCBRS2 UCBRS1 UCBRS0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
史海拾趣
|
未来数字生活想实现,Windows Embedded缺不了! 近年来,信息家电、数码产品、智能手机及各种掌上型多媒体设备成为IT产业的潮流,除了以上所提到的电子产品以外,其实有更多的嵌入式应用隐身在不为人知的角落,从小到电子手表、电子体温计、翻译机等,到大如冷气机、电冰箱、电视机,甚至是路上 ...… 查看全部问答> |
|
这是我大学的毕业设计,当时拿到题目时真不知道如何下手,花了我3个月的时间,直到论文写完,才真正理解ucos2的工作原理的,希望对有兴趣进入嵌入式系统学习的战友们有所帮助,同时也希望大家一起探讨学习。… 查看全部问答> |
|
我根据周立功开发板带的led驱动例程,根据自己对驱动的理解,修改如下,可是驱动却不能实现。 我在这里没有使用内核自带的函数write_gpio_bit(leds_table[arg],cmd),而是直接包含进了周立功开发板提供的S3C2410.h的头文件,然后自己编写驱动,直 ...… 查看全部问答> |
|
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or c 这么经典的问题都被我遇到了。 刚刚接触wince一周。写代码建立工程一直没有用MFC,而是使用的是Application 写的程序编译出来,完全没问题,可以下载到开发板跑。 今天下午试着建立个MFC工程。工程建立好之后,一句代码都没写,一句代码都没写 ...… 查看全部问答> |
|
我订制的操作系统上没有网上邻居,上网有些不方便,请问,如何添加自己的网上邻居?除了加入NETWORK USER INTERFACE组件外还需要其他什么组件? 谢谢… 查看全部问答> |




