软件计算波特率地址: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
}
上一篇:单片机 MSP430G2553 FLASH 操作
下一篇:单片机 MSP430 独立按键检测
推荐阅读最新更新时间:2024-11-12 09:23
设计资源 培训 开发板 精华推荐
- STM32G070RBT6核心板
- fe2.1模块
- LT8631HFE 200kHz、1.8V、1A 降压转换器的典型应用电路
- SI2404FS08-EVB,带有 UART 接口的 SI2404 ISOmodem 芯片评估板
- LT3008 系列的典型应用 - 3 uA IQ、20mA、45V 低压差线性稳压器
- RS485DL RS485保护电路
- 使用 NXP Semiconductors 的 MC08XS6421EK 的参考设计
- 具有线性AC适配器的单节Li +通讯座充电器
- AM1D-1212SH30-RZ 12V 1W DC/DC 转换器的典型应用
- PIC16F690DM-PCTLHS,使用 MCP6291 和 PIC16F690 的湿度传感器 PICtail 演示板
- 【EE团】TI M4开发板超低价尝鲜体验,分享心得赢百元返现!
- 6月4日上午10:00直播:英飞凌栅极驱动芯片的应用以及安富利对应的解决方案
- 罗彻斯特有奖调查:元器件日期代码限制是否仍然适用?70+份奖品先到先得!
- 直播已结束【普源精电2020新品发布会暨行业论坛】
- 免费申请 | Nordic Semiconductor nPM1300-EK PMIC 评估套件
- 下载有礼喽!2017年泰克亚太专家大讲堂第三期: 超宽带复杂电磁信号产生与实时分析技术
- 1月22日下午14:00Mouser携手Maxim邀您观看有奖直播:深入浅出可穿戴健康监测
- TI有奖直播|借助Sitara™ AM263x MCU 创造电气化的未来