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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STM32串口多機通信

          STM32串口多機通信

          作者: 時間:2013-03-25 來源:網(wǎng)絡 收藏

          的UART數(shù)據(jù)寄存器是9位,數(shù)據(jù)傳輸先傳低位(LSB)

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

          --實際應用發(fā)現(xiàn)9位數(shù)據(jù)大時候有丟包錯包問題??

          利用USART可以進行多機處理器,其原理就是使從機處于靜默模式,由主機在需要的時候發(fā)送指令喚醒從機,并傳輸數(shù)據(jù)。靜默模式特點:1、所有接收狀態(tài)位都不會被設置;2、所有的接收中斷都被禁止;3、USART_CR1寄存器中的RWU位被置1,RUW可以硬件自動控制或者在某些條件下由軟件寫。

          連接方法很簡單,主機的TX輸出與從機的RX端口直接相連,從機TX端口要經(jīng)過與門與主機RX端口連接。

          多機方式有2種:空閑幀喚醒和地址喚醒。

          空閑幀喚醒可以同時喚醒所有從機,在從機處于靜默模式時發(fā)送空閑幀(即所有位均為1的數(shù)據(jù)),喚醒多個從機,實現(xiàn)多個從機同步。

          地址喚醒可以喚醒單個從機,從機靜默時發(fā)送地址幀,從機自動對比地址,地址配對正確則該從機喚醒,否則繼續(xù)進入靜默。這樣只有被尋址者才被激活,來接收數(shù)據(jù),減少由未被尋址的接收機器參與帶來的多余的USART服務開銷。這種模式下,MSB為1的字節(jié)被認為是地址,否則被認為是數(shù)據(jù)(MSB一般為數(shù)據(jù)傳送的最高位,8位傳送則MSB為第八位;9位傳送則MSB為第九位)。在一個地址字節(jié)中,目標接收者的地址放在低4位。這4位會被接收器拿來和設置在USART_CR2寄存器中ADD位中的自身地址比較。當接收到一個和設置地址相匹配的地址字符時,RWU被清除,后面的字節(jié)將正常接收。因為RWU位已經(jīng)被清除,RXEN位會因為接收到地址符被置1。當從機再次接收到地址符,如若地址不匹配則從機再次進入靜默模式。

          程序?qū)嶋H編寫時可以注意以下3部分的設置:

          一、設置靜默模式:

          函數(shù)原形

          void USART_WakeUpConfig(USART_TypeDef* USARTx, u16 USART_WakeUp)

          其中USART_WakeUp:USART的喚醒方式:

          1、USART_WakeUp_IdleLine 空閑總線喚醒

          2、USART_WakeUp_AddressMark 地址標記喚醒

          二、地址喚醒中地址設置:

          函數(shù)原形

          void USART_SetAddress(USART_TypeDef* USARTx, u8 USART_Address)

          其中USART_Address:是設置USART 節(jié)點的地址。

          例如:USART_SetAddress(USART2, 0x5);

          三、是否進入靜默:

          函數(shù)原形

          void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState Newstate)

          其中NewState: USART 靜默模式的新狀態(tài)這個參數(shù)可以?。篍NABLE或者DISABLE。

          Address mark detection (WAKE=1)

          In this mode, bytes are recognized as addresses if their MSB is a ‘1 else they are

          considered as data. In an address byte, the address of the targeted receiver is put on the 4

          LSB. This 4-bit word is compared by the receiver with its own address which is programmed

          in the ADD bits in the USART_CR2 register.

          The USART enters mute mode when an address character is received which does not

          match its programmed address. In this case, the RWU bit is set by hardware. The RXNE flag

          is not set for this address byte and no interrupt nor DMA request is issued as the USART

          would have entered mute mode.

          It exits from mute mode when an address character is received which matches the

          programmed address. Then the RWU bit is cleared and subsequent bytes are received

          normally. The RXNE bit is set for the address character since the RWU bit has been cleared.

          The RWU bit can be written to as 0 or 1 when the receiver buffer contains no data (RXNE=0

          in the USART_SR register). Otherwise the write attempt is ignored.

          Bit 1 RWU: Receiver wakeup

          This bit determines if the USART is in mute mode or not. It is set and cleared by software

          and can be cleared by hardware when a wakeup sequence is recognized.

          0: Receiver in active mode

          1: Receiver in mute mode

          Note: 1: Before selecting Mute mode (by setting the RWU bit) the USART must first receive a

          data byte, otherwise it cannot function in Mute mode with wakeup by Idle line detection.

          2: In Address Mark Detection wakeup configuration (WAKE bit=1) the RWU bit cannot

          be modified by software while the RXNE bit is set.

          Bit 11 WAKE: Wakeup method

          This bit determines the USART wakeup method, it is set or cleared by software.

          0: Idle Line

          1: Address Mark

          “logically ANDed ” 指的是邏輯上的關(guān)系。某些情況下,不需要另外加與門電路。

          比如:板上有3個,1主2從,中間未加電平變換芯片(直連),從機的發(fā)送腳都配置成open drain輸出并帶上拉,這種情況下2個從STM32芯片的TX腳可以 直接連到主STM32芯片的RX腳。

          如果用了電平變換芯片比如MAX232,一般需要另外加與門電路。

          數(shù)字通信相關(guān)文章:數(shù)字通信原理


          通信相關(guān)文章:通信原理




          關(guān)鍵詞: 通信 串口 STM32

          評論


          相關(guān)推薦

          技術(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); })();