<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > S3C2410串口波特率的計(jì)算

          S3C2410串口波特率的計(jì)算

          作者: 時(shí)間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
          要正確計(jì)算串口波特率,首先要搞清楚芯片的時(shí)鐘工作原理,這部分在s3c2410/s3c2440datasheet上寫的比較詳細(xì),但對(duì)新手來說結(jié)合thisway同志“s3c2410完全開發(fā)流程”中的TIMER和CLOCK兩個(gè)實(shí)驗(yàn),邊做實(shí)驗(yàn)邊看資料,更容易理解。

          我這里只根據(jù)我的失敗經(jīng)驗(yàn)談一下設(shè)置波特率寄存器UBRDIVn的值的計(jì)算要注意的一個(gè)問題。

          本文引用地址:http://www.ex-cimer.com/article/201611/317242.htm

          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

          也就是說,只要知道這個(gè)UART clock 就計(jì)算出UBRDIVn 的值,下面分別講:

          1. UEXTCLK

          查手冊(cè):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.是說當(dāng)用系統(tǒng)時(shí)鐘(system clock)時(shí)UART波特率最高可達(dá)到115200,但是如果用這個(gè)UEXTCLK(external clocks for the UART operation)串口外設(shè)時(shí)鐘,可以設(shè)置115200以上的波特率。

          2. PCLK和FCLK/n

          這里又分兩種情況:使用MPLL和不使用MPLL

          我們知道s3c2410最高頻率可達(dá)266M,s3c2440最高頻率可達(dá)533M,而一般外接晶振只有幾十M,如何使幾十M變成幾百M(fèi)呢?這就是MPLL的功勞了

          s3c2410有兩個(gè)pll(phase locked loop,鎖相環(huán),在高頻中學(xué)過,可以實(shí)現(xiàn)倍頻,s3c2410的高頻就是由此電路產(chǎn)生的)。其中一個(gè)是MPLL,M即為main,用來產(chǎn)生三種時(shí)鐘信號(hào):Fclk(給CPU核供給時(shí)鐘信號(hào),我們所說的s3c2410的cpu主頻為200MHz,就是指的這個(gè)時(shí)鐘信號(hào),相應(yīng)的,1/Fclk即為cpu時(shí)鐘周期)、Hclk(為AHB bus peripherals供給時(shí)鐘信號(hào),AHB為advanced high-performance bus)、Pclk(為APB bus peripherals供給時(shí)鐘信號(hào),APB為advanced peripherals bus)。AHB和APB這兩種總線所連的外設(shè)是有區(qū)別的。AHB總線連接高速外設(shè),低速外設(shè)則通過APB總線互連。顯然,對(duì)不同總線上的外設(shè),應(yīng)該使用不同的時(shí)鐘信號(hào),AHB總線對(duì)應(yīng)Hclk,APB總線對(duì)應(yīng)Pclk。那么事先就應(yīng)該弄清楚,每條總線對(duì)應(yīng)的外設(shè)有那些,這樣在設(shè)置好時(shí)鐘信號(hào)后,對(duì)應(yīng)外設(shè)的初始化的值就要依此而確定了。

          當(dāng)不使用MPLL(即不設(shè)置MPLLCON寄存器)時(shí),外部晶振直接作為系統(tǒng)時(shí)鐘。一般外部晶振有兩個(gè),一是用于系統(tǒng)時(shí)鐘,為12MHz(或其他,由具體板子決定);一個(gè)用于實(shí)時(shí)時(shí)鐘(RTC,real time clock,根據(jù)CPU的要求送出或設(shè)定時(shí)鐘、日歷的各種數(shù)據(jù)),為32.768KHz。此時(shí),PCLK即為12MHz。

          當(dāng)使用MPLL時(shí),要通過對(duì)寄存器MPLLCON和CLKDIVN的設(shè)置來得到FCLK、HCLK和PCLK。

          得到這個(gè)UART clock(PCLK, FCLK/n or UEXTCLK ),根據(jù)公式

          UBRDIVn = (int)( UART clock / ( buad rate x 16) ) –1

          來計(jì)算就簡(jiǎn)單了。



          關(guān)鍵詞: S3C2410串口波特

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();