s3c2410/s3c2440串口波特率的计算
要正确计算串口波特率,首先要搞清楚芯片的时钟工作原理,这部分在s3c2410/s3c2440datasheet上写的比较详细,但对新手来说结合thisway同志“s3c2410完全开发流程”中的TIMER和CLOCK两个实验,边做实验边看资料,更容易理解。
我这里只根据我的失败经验谈一下设置波特率寄存器UBRDIVn的值的计算要注意的一个问题。
datasheet上UBRDIVn寄存器部分写着:
UART BAUD RATE DIVISOR REGISTER
There are three UART baud rate divisor registers including UBRDIV0, UBRDIV1 and UBRDIV2 in the UART block.
The value stored in the baud rate divisor register (UBRDIVn), is used to determine the serial Tx/Rx clock rate (baudrate) as follows:
UBRDIVn = (int)( UART clock / ( buad rate x 16) ) –1
( UART clock: PCLK, FCLK/n or UEXTCLK )
Where, UBRDIVn should be from 1 to (216-1), but can be set zero only using the UEXTCLK which should be smaller than PCLK.
For example, if the baud-rate is 115200 bps and UART clock is 40 MHz, UBRDIVn is:
UBRDIVn = (int)(40000000 / (115200 x 16) ) -1
= (int)(21.7) -1 [round to the nearest whole number]
= 22 -1 = 21
也就是说,只要知道这个UART clock 就计算出UBRDIVn 的值,下面分别讲:
1. UEXTCLK
查手册:The UART can support bit rates up to 115.2K bps using system clock. If an external device provides the UART with UEXTCLK, then the UART can operate at higher speed.是说当用系统时钟(system clock)时UART波特率最高可达到115200,但是如果用这个UEXTCLK(external clocks for the UART operation)串口外设时钟,可以设置115200以上的波特率。