Electoday 2025

ไมโครคอนโทรลเลอร์ => ARM Processors => Topic started by: tha on January 16, 2021, 07:14:07 AM

Title: STM32F1 USART
Post by: tha on January 16, 2021, 07:14:07 AM
27 Universal synchronous asynchronous receiver transmitter (USART)

Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes.
XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 768 Kbytes and 1 Mbyte.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.

ส่วนนี้ใช้กับตระกูล STM32F10xxx ทั้งหมดเว้นแต่จะระบุไว้เป็นอย่างอื่น

27.1 USART introduction

The universal synchronous asynchronous receiver transmitter (USART) เสนอวิธีการที่หยืดหยุ่นของ full-duplex data exchange กับ external equipment ที่ต้องการ an industry standard NRZ asynchronous serial data format. The USART เสนอ a very wide range ของ baud rates โดยใช้ a fractional baud rate generator.

มันรองรับ synchronous one-way communication และ half-duplex single wire communication. มันยังรองรับ the LIN (local interconnection network), Smartcard Protocol และ IrDA (infrared data association) SIR ENDEC specifications, และ modem operations (CTS/RTS). มันยอมให้ multiprocessor communication

High speed data communication สามารถเป็นได้โดยการใช้ the DMA สำหรับ multibuffer configuration.
Title: Re: STM32F1 USART
Post by: tha on January 16, 2021, 09:44:34 AM
27.2 USART main features

•    Full duplex, asynchronous communications
•    NRZ standard format (Mark/Space)
•    Fractional baud rate generator systems
      –    A common programmable transmit and receive baud rates สูงถึง 4.5 MBits/s
•    Programmable data word length (8 or 9 bits)
•    กำหนดค่าได้ stop bits - รองรับสำหรับ 1 or 2 stop bits
•    LIN Master Synchronous Break send capability and LIN slave break detection capability
      –    13-bit break generation and 10/11 bit break detection เมื่อ USART เป็น hardware ที่กำหนดค่าสำหรับ LIN
•    Transmitter clock output for synchronous transmission
•    IrDA SIR Encoder Decoder
      –    รองรับสำหรับ 3/16 bit duration for normal mode
•    Smartcard Emulation Capability
      –    The Smartcard interface รองรับ the asynchronous protocol Smartcards ตามที่กำหนดใน ISO 7816-3 standards
      –    0.5, 1.5 Stop Bits for Smartcard operation
•    Single wire half duplex communication
•    กำหนดค่าได้ multibuffer communication โดยใช้ DMA (direct memory access)
      –    Buffering ของ received/transmitted bytes ใน reserved SRAM โดยใช้ centralized DMA
•    Separate(แยกกัน) enable bits สำหรับ Transmitter and Receiver
•    Transfer detection flags:
      –    Receive buffer full
      –    Transmit buffer empty
      –    End of Transmission flags
•    Parity control:
      –    Transmits parity bit
      –    Checks parity of received data byte
•    Four error detection flags:
      –    Overrun error
      –    Noise error
      –    Frame error
      –    Parity error
•    Ten interrupt sources with flags:
      –    CTS changes
      –    LIN break detection
      –    Transmit data register empty
      –    Transmission complete
      –    Receive data register full
      –    Idle line received
      –    Overrun error
      –    Framing error
      –    Noise error
      –    Parity error
•    Multiprocessor communication - เข้าสู่ mute mode ถ้า address match ไม่เกิดขึ้น
•    Wake up from mute mode (by idle line detection or address mark detection)
•    Two receiver wakeup modes: Address bit (MSB, 9th bit), Idle line
Title: Re: STM32F1 USART
Post by: tha on January 16, 2021, 11:44:41 AM
27.3 USART functional description

The interface ถูกต่อภายนอกไปยัง device อื่นโดย three pins (ดู Figure 279). Any USART bidirectional communication ต้องการอย่างต่ำ two pins: Receive Data In (RX) และ Transmit Data Out (TX):

RX: Receive Data Input เป็น the serial data input. Oversampling techniques ถูกใช้สำหรับการกู้คืน data โดยการแยกแยะระหว่าง valid incoming data และ noise.

TX: Transmit Data Output. เมื่อ the transmitter ถูกปิดการใช้งาน, the output pin คืนกลับไปยัง IO port configuration ของมัน. เมื่อ the transmitter ถูกเปิดการใช้งานและไม่มีอะไรถูกส่ง, the TX pin จะอยู่ที่ high level. ใน single-wire และ smartcard modes, IO นี้ถูกใช้ส่งและรับ the data (ที่ USART level, data จากนั้นถูกรับบน SW_RX).

ผ่านทางพินเหล่านี้, serial data ถูก transmitted และ received ใน normal USART mode เป็น frames ประกอบด้วย:
•    An Idle Line ก่อนที่จะ transmission หรือ reception
•    A start bit
•    A data word (8 or 9 bits) least significant bit first(เป็นอันดับแรก)
•    0.5,1, 1.5, 2 Stop bits แสดงให้เห็นว่า the frame เสร็จสมบูรณ์
•    interface นี้ใช้ a fractional baud rate generator - ด้วย a 12-bit เป็นตัวเลขที่อยู่ทางขวาของจุดและ 4-bit เป็นเศษส่วน
•    A status register (USART_SR)
•    Data register (USART_DR)
•    A baud rate register (USART_BRR) - 12-bit เป็นตัวเลขที่อยู่ทางขวาของจุดและ 4-bit เป็นเศษส่วน
•    A Guardtime Register (USART_GTPR) ในกรณีของ Smartcard mode.

อ้างอิงถึง Section 27.6: USART registers สำหรับคำจำกัดความของแต่ละบิต

พินต่อไปนี้ถูกต้องการเพื่อเชื่อมต่อใน synchronous mode:
•    CK: Transmitter clock output. พินนี้ส่งออก the transmitter data clock สำหรับ synchronous transmission ตรง
      กันกับ SPI master mode (ไม่มี clock pulses บน start bit และ stop bit, และ a software มีทางเลือกที่จะส่ง a clock pulse
      บน the last data bit). ใน parallel data สามารถถูกรับแบบ synchronously บน RX. นี้สามารถถูกใช้เพื่อควบคุม peripherals ที่
      มี shift registers (ตัวอย่างเช่น LCD drivers). The clock phase และ polarity โปรแกรมได้ทาง software. ใน Smartcard
      mode, CK สามารถจัดให้มี the clock ไปยัง the smartcard.

พินต่อไปนี้ถูกต้องการใน Hardware flow control mode:
•    CTS: Clear To Send บล็อก the data transmission ที่ the end of the current transfer เมื่อ high
•    RTS: Request to send แสดงให้เห็นว่า the USART พร้อมที่จะรับ a data (เมื่อ low).

(https://i.imgur.com/MJA1MUf.png)
Title: Re: STM32F1 USART
Post by: tha on January 17, 2021, 05:04:11 AM
27.3.1 USART character description

Word length อาจถูกเลือกให้เป็นอย่างใดอย่างหนึ่ง 8 หรือ 9 bits โดยการโปรแกรม the M bit ใน the USART_CR1 register (ดู Figure 280).

The TX pin อยู่ใน low state ในระหว่าง the start bit. มันอยู่ใน high state ในระหว่าง the stop bit.

An Idle character ถูกตีความหมายว่าเป็นเฟรมทั้งหมดของ" 1" ตามด้วย the start bit ของ the next frame ซึ่งบรรจุ data (จำนวนของ "1" 's จะรวมถึงจำนวนของ stop bits).

A Break character ถูกตีความหมายบนการรับ "0"s สำหรับ a frame period. ที่ the end of the break frame the transmitter แทรกอย่างใดอย่างหนึ่ง 1 or 2 stop bits (logic "1" bit) เพื่อ acknowledge the start bit.

Transmission and reception ถูกขับโดย a common baud rate generator, the clock สำหรับแต่ละตัวนั้นถูกสร้างขึ้นเมื่อ the enable bit ถูกเซ็ตสำหรับ the transmitter and receiver ตามลำดับ

รายละเอียดของแต่ละ block ถูกให้ไว้ด้านล่างนี้.

(https://i.imgur.com/IIHDaaZ.png)
Title: Re: STM32F1 USART
Post by: tha on January 17, 2021, 09:03:35 AM
27.3.2 Transmitter

The transmitter สามารถส่ง data words ของอย่างใดอย่างหนึ่ง 8 หรือ 9 bits ขึ้นอยู่กับ the M bit status. เมื่อ the transmit enable bit (TE) ถูกเซ็ต, the data ใน the transmit shift register ถูกส่งออกไปบน the TX pin และ the corresponding clock pulses ถูกส่งออกไปบน the CK pin.

Character transmission

ในระหว่าง a USART transmission, data เลื่อนออก least significant bit เป็นอันดับแรกไปบน the TX pin. ในโหมดนี้, the USART_DR register ประกอบด้วย a buffer (TDR) ระหว่าง the internal bus และ the transmit shift register (ดู Figure 279).

ทุกๆ character ถูกนำหน้าด้วย a start bit, ซึ่งเป็น a logic level low เป็นเวลา one bit period. The character ถูกปิดท้ายด้วย จำนวนที่กำหนดค่าได้ของ stop bits.

The following stop bits ถูกรองรับโดย USART: 0.5, 1, 1.5 and 2 stop bits.

Note: The TE bit ไม่ควรถูกรีเซ็ตในระหว่าง transmission of data. การรีเซ็ต the TE bit ในระหว่าง the transmission จะทำความ
           เสียหายให้ the data บน the TX pin ดังที่ the baud rate counters จะได้รับการแช่แข็ง. The current data ที่กำลังถูกส่งจะ
           สูญหาย.

            An idle frame จะถูกส่งหลังจาก the TE bit ถูก enabled.
Title: Re: STM32F1 USART
Post by: tha on January 17, 2021, 09:59:22 AM
Configurable stop bits

จำนวนของ stop bits ที่จะถูกส่งพร้อมกับทุกๆ character สามารถถูกโปรแกรมใน Control register 2, bits 13,12.
1.    1 stop bit: นี้เป็นค่าเริ่มต้น.
2.    2 stop bits: นี้ถูกรองรับโดย USART ปกติ, single-wire และ modem modes.
3.    0.5 stop bit: ถูกใช้เมื่อ receiving data ใน Smartcard mode.
4.    1.5 stop bits: ถูกใช้เมื่อ transmitting and receiving data in Smartcard mode

An idle frame transmission จะรวม the stop bits เข้าด้วย.

A break transmission จะเป็น 10 low bits ตามด้วยจำนวนที่กำหนดค่าได้ของ stop bits (เมื่อ m = 0) และ 11 low bits ตามด้วยจำนวนที่กำหนดค่าได้ของ stop bits (เมื่อ m = 1). มันเป็นไปไม่ได้ที่จะส่ง long breaks (break ของความยาวที่มากกว่า 10/11 low bits).

(https://i.imgur.com/ytN7Zsd.png)

ขั้นตอน:
1.    เปิดการใช้งาน the USART โดยการเขียน the UE bit ใน USART_CR1 register เป็น 1.
2.    โปรแกรม the M bit ใน USART_CR1 เพื่อกำหนด the word length
3.    โปรแกรมจำนวนของ stop bits ใน USART_CR2
4.    เลือก DMA enable (DMAT) ใน USART_CR3 ถ้า Multi buffer Communication ถูกนำมาใช้. กำหนดค่า the DMA register
       ดังอธิบายใน multibuffer communication.
5.    เลือก the desired baud rate โดยใช้ the USART_BRR register.
6.    เซ็ต the TE bit ใน USART_CR1 เพื่อส่ง an idle frame เป็น first transmission.
7.    เขียน the data ที่จะส่งใน the USART_DR register (นี้จะเคลียร์ the TXE bit). ทำซ้ำอย่างนี้สำหรับแต่ละ data ที่จะถูกส่งในกรณี
       ของ single buffer.
8.    หลังจากการเขียน the last data ลงใน the USART_DR register, คอยจนกระทั่ง TC=1. นี้แสดงให้เห็นว่า the transmission
       ของ the last frame เสร็จสมบูรณ์. นี้ถูกต้องการอย่างเช่นเมื่อ the USART ถูกปิดการใช้งานหรือเข้าสู่ the Halt mode เพื่อหลีก
       เลี่ยงการเสียหาย the last transmission.
Title: Re: STM32F1 USART
Post by: tha on January 17, 2021, 10:54:30 AM
Single byte communication

The TXE bit ถูกเคลียร์เสมอโดยการเขียนไปยัง the data register.

The TXE bit ถูกเซ็ตโดย hardware และมันแสดงให้เห็น:
•    The data ถูกเคลื่อนจาก TDR ไปยัง the shift register แล้วและ the data transmission ถูกสตาร์ทแล้ว.
•    The TDR register ว่างเปล่า.
•    The next data สามารถถูกเขียนใน the USART_DR register โดยปราศจากการเขียนทับ data ก่อนหน้า.

flag นี้สร้าง an interrupt ถ้า the TXEIE bit ถูกเซ็ต

เมื่อ a transmission กำลังเกิดขึ้น, a write instruction ไปยัง the USART_DR register จะเก็บ the data ใน the TDR register และซึ่งจะถูกคัดลอกลงใน the shift register ที่ the end of the currenttransmission

เมื่อไม่มี transmission เกิดขึ้น, a write instruction ไปยัง the USART_DR register จะใส่ the data โดยตรงลงใน the shift register, the data transmission จะสตาร์ท, และ the TXE bit ถูกเซ็ตโดยทันที.

ถ้าเฟรมเดียวถูกส่ง (หลังจาก the stop bit) และ the TXE bit ถูกเซ็ต, the TC bit ไปเป็น high. An interrupt ถูกสร้างขึ้นถ้า the TCIE bit ถูกเซ็ตใน the USART_CR1 register.

หลังจากการเขียน the last data ลงใน the USART_DR register, มีข้อบังคับว่าให้คอยสำหรับ TC=1 ก่อนการปิดการใช้งาน the USART หรือการเป็นสาเหตุให้ the microcontroller เข้าสู่ the low-power mode (ดู Figure 282).

The TC bit ถูกเคลียร์โดย the following software sequence:
1.    การอ่านจาก the USART_SR register
2.    การเขียนไปยัง the USART_DR register

Note: The TC bit สามารถถูกเคลียร์โดยการเขียน '0' ไปยังมันได้อีกด้วย. ลำดับการเคลียร์นี้แนะนำเฉพาะสำหรับ Multibuffer
           communication เท่านั้น.

(https://i.imgur.com/5YjKEzi.png)
Title: Re: STM32F1 USART
Post by: tha on January 17, 2021, 01:38:52 PM
Break characters

การเซ็ต the SBK bit จะส่ง a break character. The break frame length ขึ้นอยู่กับ the M bit (see Figure 280).

ถ้า the SBK bit ถูกเซ็ตเป็น '1' a break character ถูกส่งไปบน the TX line หลังจากการเสร็จสมบูรณ์ the current character transmission. บิตนี้ถูกรีเซ็ตโดย hardware เมื่อ the break character ถูกทำให้เสร็จสมบูรณ์ (ในระหว่าง the stop bit of the break character). The USART แทรก a logic 1 bit ที่ the end of the last break frame เพื่อรับประกันการรับรู้ของ the start bit of the next frame

Note: ถ้า the software รีเซ็ต the SBK bit ก่อนการเริ่มต้นของ break transmission, the break character จะไม่ถูกส่ง. สำหรับ
           สอง breaks ที่ติดตามกัน, the SBK bit ควรถูกเซ็ตหลังจาก the stop bit ของ break ก่อนหน้า.

Idle characters

การเซ็ต the TE bit จะขับ the USART เพื่อส่ง an idle frame ก่อน the first data frame.
Title: Re: STM32F1 USART
Post by: tha on January 18, 2021, 06:04:03 AM
27.3.3 Receiver

The USART สามารถรับ data words ของอย่างใดอย่างหนึ่ง 8 หรือ 9 bits ขึ้นอยู่กับ the M bit ใน the USART_CR1 register.

Start bit detection

ใน the USART, the start bit ถูกตรวจพบเมื่อ a specific sequence of samples ถูกรู้จัก.
ลำดับนี้คือ : 1 1 1 0 X 0 X 0 X 0 0 0 0.

(https://i.imgur.com/MnhRFU3.png)

Note:  ถ้า the sequence ไม่เสร็จสมบูรณ์, the start bit detection จะแท้งและ the receiver กลับคืนสู่ the idle state (ไม่มี flag
            ถูก set) ที่มันคอยสำหรับ a falling edge.

            The start bit ถูกยืนยัน (RXNE flag set, interrupt ถูกสร้างขึ้นถ้า RXNEIE=1) ถ้า the 3 sampled bits อยู่ที่ 0 (first
            sampling บน the 3rd, 5th and 7th bits พบว่า the 3 bits อยู่ที่ 0 และ second sampling บน the 8th, 9th and
            10th bits พบว่า the 3 bits อยู่ที่ 0 อีกด้วย)

            The start bit ถูกตรวจสอบว่าใช้ได้ (RXNE flag set, interrupt ถูกสร้างขึ้นถ้า RXNEIE=1) แต่ the NE noise flag ถูก set
            ถ้า, สำหรับทั้งสองการสุ่มตัวอย่าง, อย่างน้อย 2 ใน the 3 sampled bits อยู่ที่ 0 (sampling on the 3rd, 5th and 7th bits
            and sampling on the 8th, 9th and 10th bits). ถ้าเงื่อนไขนี้ไม่ถูกตรงตาม, the start detection จะแท้งและ the
            receiver กลับคืนสู่ the idle state (ไม่มี flag ถูก set)

            ถ้า, สำหรับหนึ่งของ the samplings (sampling on the 3rd, 5th and 7th bits หรือ sampling on the 8th, 9th and
            10th bits), 2 ใน the 3 bits ถูกพบว่าอยู่ที่ 0, the start bit ถูกตรวจสอบว่าใช้ได้แต่ the NE noise flag bit ถูก set..
Title: Re: STM32F1 USART
Post by: tha on January 18, 2021, 06:49:49 AM
Character reception

ในระหว่าง a USART reception, data เลื่อนเข้า least significant bit เป็นอันดับแรกผ่านทาง the RX pin. ในโหมดนี้, the USART_DR register ประกอบด้วย a buffer (RDR) ระหวาง the internal bus and the received shift register.

ขั้นตอน:
1.    เปิดการใช้งาน the USART โดยการเขียน the UE bit ใน USART_CR1 register เป็น 1.
2.    โปรแกรม the M bit ใน USART_CR1 เพื่อกำหนด the word length
3.    โปรแกรมจำนวนของ stop bits ใน USART_CR2
4.    เลือก DMA enable (DMAT) ใน USART_CR3 ถ้า Multi buffer Communication ถูกนำมาใช้. กำหนดค่า the DMA register
       ดังอธิบายใน multibuffer communication. STEP 3
5.    เลือก the desired baud rate โดยใช้ the baud rate register USART_BRR.
6.    เซ็ต the RE bit USART_CR1. นี้เปิดการใช้งาน the receiver ซึ่งเริ่มการค้นหาสำหรับ a start bit.

เมื่อ a character ถูกรับ
•    The RXNE bit ถูก set. มันแสดงให้เห็นว่า the content of the shift register ถูกส่งถ่ายไปยัง the RDR. กล่าวอีกนัยหนึ่ง, data
      ถูกรับแล้วและสามารถถูกอ่าน (เช่นเดียวกับ associated error flags ของมัน).
•    An interrupt ถูกสร้างขึ้นถ้า the RXNEIE bit ถูก set.
•    The error flags สามารถถูกเซ็ตถ้า a frame error, noise or an overrun error ถูกตรวจพบในระหว่าง reception
•    ใน multibuffer, RXNE ถูกเซ็ตหลังจากทุกๆ byte ถูกรับและถูกเคลียร์โดย the DMA อ่านไปยัง the Data Register.
•    ใน single buffer mode, การเคลียร์ the RXNE bit ถูกกระทำโดย a software โดยอ่านไปยัง the USART_DR register. The
      RXNE flag สามารถถูกเคลียร์โดยการเขียนศูนย์ไปยังมันได้อีกด้วย. The RXNE bit ต้องถูกเคลียร์ก่อน the end of the reception
      of the next character เพื่อหลีกเลี่ยง an overrun error.

Note: The RE bit ไม่ควรถูกรีเซ็ตในขณะที่กำลังรับ data. ถ้า the RE bit ถูกปิดการใช้งานในระหว่าง reception, the reception of
           the current byte จะถูกยกเลิก.
Title: Re: STM32F1 USART
Post by: tha on January 19, 2021, 06:27:58 AM
Break character

เมื่อ a break character ถูกรับ received, the USART รับมือมันดั่ง a framing error.

Idle character

เมื่อ an idle frame ถูกตรวจพบ, จะมีขั้นตอนเดียวกันกับ a data received character บวก an interrupt ถ้า the IDLEIE bit ถูก set.

Overrun error

An overrun error เกิดขึ้นเมื่อ a character ถูกรับเมื่อ RXNE ยังไม่ถูก reset. Data ไม่สามารถถูกส่งถ่ายจาก the shift register ไปยัง the RDR register จนกระทั่ง the RXNE bit ถูกเคลียร์.

The RXNE flag ถูก set หลังจากทุกๆ byte ถูกรับ. An overrun error เกิดขึ้นถ้า RXNE flag ถูก set เมื่อ the next data ถูกรับหรือ the previous DMA request ยังไม่ได้ถูกบริการ. เมื่อ an overrun error เกิดขึ้น :
•    The ORE bit ถูก set.
•    The RDR content จะไม่สูญหาย. The previous data สามารถใช้ประโยชน์ได้เมื่อการอ่านไปยัง USART_DR ถูกดำเนินการ.
•    The shift register จะถูกเขียนทับ. หลังจากจุดนี้, data ใดๆที่ถูกรับในระหว่าง overrun จะสูญหาย.
•    An interrupt ถูกสร้างขึ้นถ้าอย่างใดอย่างหนึ่ง the RXNEIE bit ถูก set หรือทั้ง the EIE and DMAR bits ถูก set.
•    The ORE bit ถูก reset โดยการอ่านไปยัง the USART_SR register ตามด้วย a USART_DR register read operation

Note: The ORE bit, เมื่อ set, แสดงให้เห็นว่าอย่างน้อยt 1 data จะสูญหาย. มาสองความเป็นไปได้ :
•    ถ้า RXNE=1, ดังนั้น the last valid data ถูกเก็บใน the receive register RDR และสามารถถูกอ่าน,
•    ถ้า RXNE=0, ดังนั้นมันหมายความว่า the last valid data ถูกอ่านไปแล้วและดังนั้นไม่มีอะไรที่ต้องถูกอ่านใน the RDR. กรณีนี้
      สามารถเกิดขึ้นเมื่อ the last valid data ถูกอ่านใน the RDR ในเวลาเดียวกันที่ the new (and lost) data ถูกรับ. มันอาจเกิดขึ้น
      เมื่อ the new data ถูกรับในระหว่าง the reading sequence (ระหว่าง the USART_SR register read access และ the
      USART_DR read access).
Title: Re: STM32F1 USART
Post by: tha on January 19, 2021, 07:28:37 AM
Noise error

Over-sampling techniques ถูกใช้ (ยกเว้นใน synchronous mode) สำหรับการกู้คืน data โดยการแยกแยะระหว่าง valid incoming data และ noise.

(https://i.imgur.com/U8h5cxA.png)

(https://i.imgur.com/SW2Jdbd.png)

เมื่อ noise ถูกตรวจพบใน a frame:
•    The NE ถูก set ที่ the rising edge ของ the RXNE bit.
•    The invalid data ถูกส่งถ่ายจาก the Shift register ไปยัง the USART_DR register.
•    ไม่มี interrupt ถูกสร้างขึ้นในกรณีของ single byte communication. อย่างไรก็ตามบิตนี้ rises ในเวลาเดียวกันกับ the RXNE bit
      ซึ่งสร้าง an interrupt ของมันเอง. ในกรณีของ multibuffer communication an interrupt จะถูกปล่อยออกมาถ้า the EIE bit
      ถูก set ใน the USART_CR3 register.

The NE bit ถูก reset โดย a USART_SR register read operation ตามด้วย a USART_DR register read operation.
Title: Re: STM32F1 USART
Post by: tha on January 19, 2021, 09:09:38 AM
Framing error

A framing error ถูกตรวจพบเมื่อ :

The stop bit ไม่ถูกรับรู้บน reception ในเวลาที่คาดไว้, ตามด้วยอย่างใดอย่างหนึ่ง a desynchronization หรือ excessive noise.

เมื่อ the framing error ถูกตรวจพบ:
•    The FE bit ถูก set โดย hardware
•    The invalid data ถูกส่งถ่ายจาก the Shift register ไปยัง the USART_DR register.
•    ไม่มี interrupt ถูกสร้างขึ้นในกรณีของ single byte communication. อย่างไรก็ตามบิตนี้ rises ในเวลาเดียวกันกับ the RXNE bit
      ซึ่งสร้าง an interrupt ของมันเอง. ในกรณีของ multibuffer communication an interrupt จะถูกปล่อยออกมาถ้า the EIE bit
      ถูก set ใน the USART_CR3 register.

The FE bit ถูก reset โดย a USART_SR register read operation ตามด้วย a USART_DR register read operation.
Title: Re: STM32F1 USART
Post by: tha on January 19, 2021, 10:02:17 AM
Configurable stop bits during reception

จำนวนของ stop bits ที่ถูกรับสามารถถูกกำหนดค่าผ่านทาง the control bits ของ Control Register 2 - มันสามารถเป็นอย่างใดอย่างหนึ่ง 1 or 2 in normal mode และ 0.5 or 1.5 in Smartcard mode.
1.    0.5 stop bit (reception in Smartcard mode): ไม่มีการสุ่มถูกทำสำหรับ 0.5 stop bit. เป็นผลให้, ไม่มี framing error และ
       ไม่มี break frame สามารถถูกตรวจพบเมื่อ 0.5 stop bit ถูกเลือก.
2.    1 stop bit: การสุ่มสำหรับ 1 stop Bit ถูกทำบน the 8th, 9th and 10th samples
3.    1.5 stop bits (Smartcard mode): เมื่อส่งใน Smartcard mode, the device ต้องเช็คว่า the data ถูกส่งอย่างถูกต้อง. ดังนั้น
       the receiver block ต้องถูกเปิดการใช้งาน(RE =1 in the USART_CR1 register) และ the stop bit ถูกเช็คเพื่อ test ถ้า the
       smartcard ถูกตรวจพบ a parity error. ในกรณีของ a parity error, the smartcard บังคับให้ the data signal low ใน
       ระหว่างการสุ่ม - NACK signal-, ซึ่งถูกป้ายชื่อว่าเป็น a framing error. ดังนั้น, the FE flag ถูก set พร้อมด้วย the RXNE ที่ the
       end of the 1.5 stop bit. การสุ่มสำหรับ 1.5 stop bits ถูกทำบน the 16th, 17th and 18th samples (1 baud clock
       period หลังจากการเริ่มต้นของ the stop bit). The 1.5 stop bit สามารถถูกแยกออกเป็นส่วนลงใน 2 ส่วน: one 0.5 baud clock
       period ในระหว่างซึ่งไม่มีอะไรเกิดขึ้น, ตามด้วย 1 normal stop bit period ในระหว่างซึ่งการสุ่มเกิดขึ้นครึ่งทางผ่านไป. Refer to
       Section 27.3.11 for more details.
4.    2 stop bits: Sampling สำหรับ 2 stop bits ถูกทำบน the 8th, 9th and 10th samples of the first stop bit. ถ้า a
       framing error ถูกตรวจพบในระหว่าง the first stop bit the framing error flag จะถูก set. The second stop bit ไม่ถูกเช็ค
       สำหรับ framing error. The RXNE flag จะถูก set ที่ the end of the first stop bit.
Title: Re: STM32F1 USART
Post by: tha on January 19, 2021, 11:25:29 AM
27.3.4 Fractional baud rate generation

The baud rate สำหรับ the receiver and transmitter (Rx and Tx) ทั้งคู่ถูกเซ็ตที่ค่าเดียวกันดังที่โปรแกรมใน the Mantissa and Fraction values of USARTDIV.

(https://i.imgur.com/clGfCNE.png)

USARTDIV คือ an unsigned fixed point number ที่ถูกโค้ดใน the USART_BRR register.

Note: The baud counters ถูกอัปเดตด้วย the new value of the Baud registers หลังจากการเขียนไปยัง USART_BRR. ด้วยเหตุนี้
           the Baud rate register value ไม่ควรถูกเปลี่ยนในระหว่าง communication.

How to derive USARTDIV from USART_BRR register values

Example 1:
ถ้า DIV_Mantissa = 0d27 and DIV_Fraction = 0d12 (USART_BRR = 0x1BC), ดังนั้น
Mantissa (USARTDIV) = 0d27
Fraction (USARTDIV) = 12/16 = 0d0.75
ดังนั้น USARTDIV = 0d27.75

Example 2:
เพื่อโปรแกรม USARTDIV = 0d25.62
นี้นำไปสู่ :
DIV_Fraction = 16*0d0.62 = 0d9.92
จำนวนจริงที่ใกล้ที่สุดคือ 0d10 = 0xA
DIV_Mantissa = mantissa (0d25.620) = 0d25 = 0x19
ดังนั้น, USART_BRR = 0x19A ด้วยเหตุนี้ USARTDIV = 0d25.625

Example 3:
เพื่อโปรแกรม USARTDIV = 0d50.99
นี้นำไปสู่ :
DIV_Fraction = 16*0d0.99 = 0d15.84
จำนวนจริงที่ใกล้ที่สุดคือ 0d16 = 0x10 => overflow of DIV_frac[3:0] => ตัวทศต้องถูกบวกขึ้นไปยัง the mantissa
DIV_Mantissa = mantissa (0d50.990 + carry) = 0d51 = 0x33
ดังนั้น, USART_BRR = 0x330 ด้วยเหตุนี้ USARTDIV = 0d51.000

(https://i.imgur.com/Xd5AzfY.png)

Note: ยิ่ง the CPU clock ต่ำลงเท่าไหร่การต่ำลงนี้จะเป็นความแม่นยำสำหรับ a particular Baud rate. ค่าจำกัดบนของ the
           achievable baud rate สามารถถูกคงที่ด้วย data นี้.
           เฉพาะ USART1 ถูก clocked ด้วย PCLK2 (72 MHz max). USARTs อื่นถูก clocked ด้วย PCLK1 (36 MHz max).
Title: Re: STM32F1 USART
Post by: tha on January 20, 2021, 06:17:10 AM
27.3.5 USART receiver's tolerance to clock deviation

The USART's asynchronous receiver ทำงานได้อย่างถูกต้องเฉพาะถ้า the total clock system deviation มีขนาดเล็กกว่า the USART receiver tolerance. สาเหตุที่ทำให้เกิดผลรวม the total deviation คือ:
•    DTRA: Deviation เนื่องจาก the transmitter error (ซึ่งรวมถึง the deviation of the transmitter local oscillator อีกด้วย)
•    DQUANT: Error เนื่องจาก the baud rate quantization of the receiver
•    DREC: Deviation of the receiver's local oscillator
•    DTCL: Deviation เนื่องจาก the transmission line (โดยทั่วไปเนื่องจาก the transceivers ที่สามารถทำให้เกิดความไม่สมมาตร
      ระหว่าง the low-to-high transition timing และ the high-to-low transition timing)

      DTRA + DQUANT + DREC + DTCL < USART receiver tolerance

The USART receiver tolerance ในการรับ data อย่างถูกต้องคือเท่ากับ the maximum tolerated deviation และขึ้นอยู่กับตัวเลือกต่อไปนี้:
•    10- or 11-bit character length ถูกกำหนดโดย the M bit ใน the USART_CR1 register
•    ใช้ fractional baud rate หรือไม่

(https://i.imgur.com/RhPkxzh.png)

Note: ตัวเลขที่ระบุใน Table 193 and Table 194 อาจแตกต่างกันเล็กน้อยในกรณีพิเศษเมื่อ the received frames บรรจุ some Idle frames ของ 10-bit ครั้งพอดิบพอดีเมื่อ M=0 (11-bit ครั้งเมื่อ M=1).
Title: Re: STM32F1 USART
Post by: tha on January 20, 2021, 08:15:28 AM
27.3.6 Multiprocessor communication

มีความเป็นไปได้ของ performing multiprocessor communication ด้วย the USART (หลาย USARTs ถูกต่อกันใน a network). ตัวอย่างเช่น, หนึ่งของ the USARTs สามารถเป็น the master, TX output ของมันถูกต่อถึง the RX input ของ the other USART. USART อื่นๆเป็น slaves,  TX outputs ตามลำดับของพวกมันถูกลอจิก AND เข้าด้วยกันและต่อถึง the RX input of the master.

ใน multiprocessor configurations มันมักจะเป็นที่น่าพอใจว่าเฉพาะ the intended message recipient ควรรับอย่างแข็งขัน the full message contents, ดังนั้นจึงลด redundant USART service overhead สำหรับทุก non addressed receivers.

The non addressed devices อาจถูกวางใน mute mode โดยวิธีของ the muting function. ใน mute mode:
•    ไม่มี the reception status bits ที่สามารถถูก set.
•    ทุก the receive interrupts ถูกยับยั้ง.
•    The RWU bit ใน USART_CR1 register ถูก set เป็น 1. RWU สามารถถูกควบคุมโดยอัตโนมัติโดย hardware หรือถูกเขียนโดย
      software ภายใต้เงื่อนไขบางประการ.

The USART สามารถเข้าสู่หรือออกจาก mute mode โดยใช้หนึ่งในสอง methods, ขึ้นอยู่กับ the WAKE bit ใน the USART_CR1 register:
•    Idle Line detection ถ้า the WAKE bit ถูก reset,
•    Address Mark detection ถ้า the WAKE bit ถูก set.
Title: Re: STM32F1 USART
Post by: tha on January 20, 2021, 09:32:59 AM
Idle line detection (WAKE=0)

The USART เข้าสู่ mute mode เมื่อ the RWU bit ถูกเขียนเป็น 1.

มัน wakes up เมื่อ an Idle frame ถูกตรวจพบ. แล้ว the RWU bit ถูกเคลียร์โดย hardware แต่ the IDLE bit ไม่ถูก set ใน the USART_SR register. RWU สามารถถูกเขียนเป็น 0 โดย software ได้อีกด้วย.

ตัวอย่างของ mute mode behavior โดยใช้ idle line detection ถูกให้ไว้ใน Figure 285.

(https://i.imgur.com/q02b4tb.png)
Title: Re: STM32F1 USART
Post by: tha on January 20, 2021, 10:35:25 AM
Address mark detection (WAKE=1)

ในโหมดนี้, bytes ถูกรับรู้เป็น addresses ถ้า MSB ของมันเป็น '1' ถ้าเป็นอย่างอื่นพวกมันถูกพิจารณาว่าเป็น data. ใน an address byte, the address ของ the targeted receiver ถูกใส่บน the 4 LSB. 4-bit word นี้ถูกเปรียบเทียบโดย the receiver กับ address ของมันซึ่งถูกโปรแกรมใน the ADD bits ใน the USART_CR2 register.

The USART เข้าสู่ mute mode เมื่อ an address character ที่ถูกรับซึ่งไม่ตรงกันกับ programmed address ของมัน. ในกรณีนี้, the RWU bit ถูก set โดย hardware. The RXNE flag ไม่ถูก set สำหรับ address byte นี้และไม่มี interrupt หรือ DMA request ถูกปล่อยออกเพราะ the USART จะเข้าสู่ mute mode.

มันออกจาก mute mode เมื่อ an address character ที่ถูกรับซึ่งตรงกันกับ the programmed address. หลังจากนั้น the RWU bit ถูกเคลียร์และ bytes ที่ตามมาถูกรับตามปกติ. The RXNE bit ถูก set สำหรับ the address character ตั้งแต่ the RWU bit ถูกเคลียร์แล้ว.

The RWU bit สามารถถูกเขียนให้เป็น 0 หรือ 1 เมื่อ the receiver buffer บรรจุ no data (RXNE=0 ใน the USART_SR register). มิฉะนั้น the write attempt จะถูกเพิกเฉย.

ตัวอย่างของ mute mode behavior โดยใช้ address mark detection ถูกให้ไว้ใน Figure 286.

(https://i.imgur.com/8vlz1aG.png)
Title: Re: STM32F1 USART
Post by: tha on January 21, 2021, 07:25:03 AM
27.3.7 Parity control

Parity control (การสร้างขึ้นของ parity bit in transmission และ parity checking in reception) สามารถถูกเปิดการใช้งานโดยการเซ็ต the PCE bit in the USART_CR1 register. ขึ้นอยู่กับ the frame length ที่กำหนดโดย the M bit, the possible USART frame formats เป็นอย่างที่รายการใน Table 195.

(https://i.imgur.com/vSWrHZQ.png)

Note: ในกรณีของ wake up โดย an address mark, the MSB bit ของ the data ถูกคำนึงถึงและไม่มี the parity bit

Even parity: the parity bit ถูกคำนวณเพื่อให้ได้จำนวนคู่ของ "1s" ภายใน the frame ที่ทำมาจาก the 7 or 8 LSB bits (ขึ้นอยู่กับว่า M เท่ากันกับ 0 or 1) และ the parity bit.

Ex: data=00110101; 4 bits set => parity bit จะเป็น 0 ถ้า even parity ถูกเลือก (PS bit in USART_CR1 = 0).

Odd parity: the parity bit ถูกคำนวณเพื่อให้ได้จำนวนคี่ของ "1s" ภายใน the frame ที่ทำมาจาก the 7 or 8 LSB bits (ขึ้นอยู่กับว่า M เท่ากันกับ 0 or 1) และ the parity bit.

Ex: data=00110101; 4 bits set => parity bit จะเป็น 0 ถ้า odd parity ถูกเลือก (PS bit in USART_CR1 = 1).

Transmission mode: ถ้า the PCE bit ถูก set ใน USART_CR1, หลังจากนั้น the MSB bit ของ the data ที่เขียนใน the data register ถูกส่งแต่ถูกเปลี่ยนโดย the parity bit (จำนวนคู่ของ "1s" ถ้า even parity ถูกเลือก (PS=0) หรือจำนวนคี่ของ "1s" ถ้า odd parity ถูกเลือก (PS=1)). ถ้า the parity check ล้มเหลว, the PE flag ถูก set ใน the USART_SR register และ an interrupt ถูกสร้างขึ้นถ้า PEIE ถูก set ใน the USART_CR1 register.
Title: Re: STM32F1 USART
Post by: tha on January 21, 2021, 08:47:46 AM
27.3.8 LIN (local interconnection network) mode

The LIN mode ถูกเลือกโดยการเซ็ต the LINEN bit in the USART_CR2 register. In LIN mode, บิตต่อไปนี้ต้องถูกเก็บที่เคลียร์:
•    STOP[1:0], CLKEN in the USART_CR2 register
•    SCEN, HDSEL and IREN in the USART_CR3 register.

LIN transmission

ขั้นตอนเดียวกันที่อธิบายไว้ใน Section 27.3.2 ต้องถูกประยุกต์ใช้สำหรับ LIN Master transmission มากกว่าสำหรับ normal USART transmission มีข้อแตกต่างดังนี้:
•    เคลียร์ the M bit เพื่อกำหนดค่า 8-bit word length.
•    เซ็ต the LINEN bit เพื่อเข้าสู่ LIN mode. ในกรณีนี้, เซ็ต the SBK bit ส่ง 13 '0' bits เป็น a break character. หลังจากนั้น a
      bit ของค่า '1' ถูกส่งเพื่อยอมให้ the next start detection.

LIN reception

A break detection circuit มีให้ใช้ใน the USART. The detection เป็นอิสระโดยสิ้นเชิงจาก the normal USART receiver. A break สามารถถูกตรวจพบเมื่อไหร่ก็ตามที่มันเกิดขึ้น, ในระหว่าง idle state หรือในระหว่าง a frame.

เมื่อ the receiver ถูกเปิดการใช้งาน (RE=1 in USART_CR1), the circuit มองไปที่ the RX input สำหรับ a start signal. วิธีสำหรับการตรวจพบ start bits คือวิธีเดียวกันเมื่อค้นหา break characters หรือ data. หลังจาก a start bit ถูกตรวจพบแล้ว, the circuit จะสุ่ม the next bits เหมือนกันเป๊ะสำหรับ the data (on the 8th, 9th and 10th samples). ถ้า 10 (เมื่อ the LBDL = 0 in
USART_CR2) หรือ 11 (เมื่อ LBDL=1 in USART_CR2) บิตซึ่งตามกันมาถูกตรวจพบว่าเป็น '0', และถูกตามด้วย a delimiter character, the LBD flag ถูก set in USART_SR. ถ้า the LBDIE bit=1, an interrupt ถูกสร้างขึ้น. ก่อนที่จะตรวจสอบความถูกต้อง the break, the delimiter ถูกเช็คสำหรับดังมันบ่งชี้ว่า the RX line กลับคืนสู่ a high level.

ถ้า a '1' ถูกสุ่มก่อน the 10 or 11 เกิดขึ้น, the break detection circuit ยกเลิก the current detection และค้นหาสำหรับ a start bit อีกครั้ง.

ถ้า the LIN mode ถูก disabled (LINEN=0), the receiver ทำงานต่อไปดั่ง normal USART, โดยปราศจากการคำนึงถึง the break detection.

ถ้า the LIN mode ถูก enabled (LINEN=1), ทันทีที่ a framing error เกิดขึ้น (เช่น stop bit ถูกตรวจพบที่ '0', ซึ่งจะเป็นกรณีของ break frame ใดๆ), the receiver หยุดจนกระทั่ง the break detection circuit รับอย่างใดอย่างหนึ่ง a '1', ถ้า the break word ไม่เสร็จสมบูรณ์, หรือ a delimiter character ถ้า a break ถูกตรวจพบแล้ว.

The behavior of the break detector state machine และ the break flag ถูกแสดงบน the Figure 287. Examples of break frames ถูกให้ไว้บน Figure 288.

(https://i.imgur.com/tFV90Ae.png)

(https://i.imgur.com/mER9PWi.png)
Title: Re: STM32F1 USART
Post by: tha on January 22, 2021, 06:44:25 AM
27.3.9 USART synchronous mode

The synchronous mode ถูกเลือกโดยการเขียน the CLKEN bit in the USART_CR2 register เป็น 1. ใน synchronous mode, บิตต่อไปนี้ต้องถูกเก็บไว้ที่เคลียร์ :
•    LINEN bit in the USART_CR2 register,
•    SCEN, HDSEL and IREN bits in the USART_CR3 register.

The USART ยอมให้ผู้ใช้ควบคุม a bidirectional synchronous serial communications ใน master mode. The CK pin คือ the output ของ the USART transmitter clock. ไม่มี clock pulses ถูกส่งไปยัง the CK pin ในระหว่าง start bit and stop bit. ขึ้นอยู่กับสถานะของ the LBCL bit in the USART_CR2 register clock pulses จะถูกสร้างหรือไม่ถูกสร้างในระหว่าง the last valid data bit (address mark). The CPOL bit in the USART_CR2 register ยอมให้ผู้ใช้เลือก the clock polarity, และ the CPHA bit in the USART_CR2 register ยอมให้ผู้ใช้เลือก the phase of the external clock (see Figure 289, Figure 290 and Figure 291).

ในระหว่าง idle, การเริ่มต้นและการส่ง break, the external CK clock ไม่ถูกทำให้ทำงาน.

In synchronous mode the USART transmitter ทำงานเหมือนกันเป๊ะกับใน asynchronous mode. แต่ดังที่ CK ถูก synchronized กับ TX (สอดคล้องกันกับ CPOL and CPHA), the data บน TX จะ synchronous.

ในโหมดนี้ the USART receiver ทำงานในวิธีที่ต่างไปเมื่อเทียบกับ the asynchronous mode. ถ้า RE=1, the data ถูกสุ่มบนn CK (rising or falling edge, ขึ้นอยู่กับ CPOL and CPHA), ปราศจาก oversampling ใดๆ. A setup and a hold time ต้องถูกเคารพ (ซึ่งขึ้นอยู่กับ the baud rate: 1/16 bit ครั้ง).

Note: The CK pin ทำงานร่วมกันกับ the TX pin. ดังั้น, the clock ถูกจัดให้มีเฉพาะถ้า the transmitter ถูก enabled (TE=1) และ
           a data กำลังถูกส่ง (the data register USART_DR ถูกเขียน). นี้หมายความว่ามันเป็นไปไม่ได้ที่จะรับ a synchronous data
           โดยปราศจากการส่ง data.

           The LBCL, CPOL and CPHA bits ต้องถูกเลือกเมื่อทั้ง the transmitter and the receiver ถูก disabled (TE=RE=0)
           เพื่อให้แน่ใจว่า the clock pulses ทำหน้าที่ได้อย่างถูกต้อง. บิตเหล่านี้ไม่ควรถูกเปลี่ยนในขณะที่ the transmitter หรือ the
           receiver ถูก enabled.

           ขอแนะนำว่า TE and RE ถูก set ใน the same instruction เพื่อลด the setup and the hold time of the receiver.

           The USART รองรับ master mode เท่านั้น: มันไม่สามารถรับหรือส่ง data ให้สัมพันธ์กับ an input clock (CK เป็น an
           output เสมอ).

(https://i.imgur.com/lChSf2q.png)

(https://i.imgur.com/VLO4T3d.png)

Note: หน้าที่ของ CK แตกต่างไปใน Smartcard mode. อ้างอิงถึง the Smartcard mode section for more details.
Title: Re: STM32F1 USART
Post by: tha on January 22, 2021, 09:07:07 AM
27.3.10 Single-wire half-duplex communication

The single-wire half-duplex mode ถูกเลือกโดยการเซ็ต the HDSEL bit in the USART_CR3 register. ในโหมดนี้, บิตต่อไปนี้ต้องถูกเก็บไว้ที่เคลียร์:
•    LINEN and CLKEN bits in the USART_CR2 register,
•    SCEN and IREN bits in the USART_CR3 register.

The USART สามารถถูกกำหนดค่าให้เป็นไปตาม a single-wire half-duplex protocol. ใน single-wire half-duplex mode, the TX and RX pins ถูกต่อภายใน. การเลือกระหว่าง half และ full-duplex communication ถูกทำด้วย a control bit 'HALF DUPLEX SEL' (HDSEL in USART_CR3).

ทันทีที่ HDSEL ถูกเขียนเป็น 1:
•    RX ไม่ได้ถูกใช้งานอีกต่อไป,
•    TX ถูกปลดปล่อยเสมอเมื่อไม่มี data ถูกส่ง. ดังนั้น, มันทำงานเป็น a standard IO ใน idle หรือใน reception. มันหมายความว่า the
      IO ต้องถูกกำหนดค่าดังนั้น TX ถูกกำหนดค่าเป็น floating input (หรือ output high open-drain) เมื่อไม่ถูกขับโดย the USART.

นอกเหนือจากนี้, the communications ยังคล้ายกับที่ทำใน normal USART mode. ความขัดแย้งใน the line ต้องได้รับการจัดการโดย the software (โดยใช้ a centralized arbiter, เป็นต้น). โดยเฉพาะอย่างยิ่ง, the transmission จะไม่ถูกปิดกั้นโดย hardware และยังคงเกิดขึ้นทันทีที่ a data ถูกเขียนใน the data register ในขณะ the TE bit ถูก set.
Title: Re: STM32F1 USART
Post by: tha on January 23, 2021, 06:09:12 AM
27.3.11 Smartcard

The Smartcard mode ถูกเลือกโดยการเซ็ต the SCEN bit in the USART_CR3 register. ใน Smartcard mode, บิตต่อไปนี้ต้องถูกเก็บไว้ที่เคลียร์:
•    LINEN bit in the USART_CR2 register,
•    HDSEL and IREN bits in the USART_CR3 register.

นอกจากนี้, the CLKEN bit อาจถูกเซ็ตเพื่อจัดให้มี a clock ไปยัง the smartcard.

The Smartcard interface ถูกออกแบบเพื่อรองรับ asynchronous protocol Smartcards ดังที่กำหนดใน the ISO 7816-3 standard. The USART ควรถูกกำหนดค่าเป็น:
•    8 bits บวก parity: ที่ M=1 and PCE=1 in the USART_CR1 register
•    1.5 stop bits เมื่อ transmitting and receiving : ที่ STOP='11' in the USART_CR2 register.

Note: มันเป็นไปได้ที่จะเลือก 0.5 stop bit สำหรับ receiving ได้อีกด้วยแต่ขอแนะนำให้ใช้ 1.5 stop bits สำหรับทั้ง transmitting
           and receiving เพื่อหลีกเลี่ยงการสวิทช์ระหว่าง the two configurations.

Figure 293 แสดงตัวอย่างของอะไรที่สามารถถูกมองเห็นได้บน the data line ที่มีและไม่มี parity error.

(https://i.imgur.com/mL8gMo4.png)

เมื่อถูกต่อถึง a smartcard, the USART TX output ขับ a bidirectional line ที่ถูกขับโดย the smartcard ได้อีกด้วย. The TX pin ต้องถูกกำหนดค่าเป็น open drain.
Title: Re: STM32F1 USART
Post by: tha on January 23, 2021, 06:45:21 AM
Smartcard คือ a single wire half duplex communication protocol.
•    Transmission ของ data จาก the transmit shift register ถูกรับประกันว่าถูกหน่วงเวลาอย่างน้อย 1/2 baud clock. ใน normal
      operation a full transmit shift register จะสตาร์ทการเลื่อนบน the next baud clock edge. ใน Smartcard mode การส่งนี้
      ถูกหน่วงเวลาออกไปโดยรับประกัน 1/2 baud clock.
•    ถ้า a parity error ถูกตรวจพบในระหว่างการรับของ a frame ที่โปรแกรมด้วย a 0.5 or 1.5 stop bit period, the transmit line
      ถูก pulled low เป็นเวลา a baud clock period หลังจากการเสร็จสมบูรณ์ของ the receive frame. นี้แสดงให้ the Smartcard
      ทราบว่า the data ที่ส่งไปยัง USART ไม่ถูกรับอย่างถูกต้อง.  NACK signal นี้ (pulling transmit line low เป็นเวลา 1 baud
      clock) จะเป็นเหตุให้ a framing error บน the transmitter side (กำหนดค่าด้วย 1.5 stop bits). The application สามารถ
      จัดการส่งซ้ำ data สอดคล้องกันกับ the protocol. A parity error ถูก 'NACK โดย the receiver ถ้า the NACK control bit 
      ถูก set, มิฉะนั้น a NACK จะไม่ถูกส่ง.
Title: Re: STM32F1 USART
Post by: tha on January 23, 2021, 09:49:28 AM
•    การถือสิทธิ์ของ the TC flag สามารถถูกหน่วงเวลาโดยการโปรแกรม the Guard Time register. ใน normal operation, TC ถูก
      ถือสิทธิ์เมื่อ the transmit shift register ว่างเปล่าและไม่มี further transmit requests ยังไม่เสร็จ. ใน Smartcard mode an
      empty transmit shift register ทริก the guard time counter ให้นับขึ้นไปยังค่าที่โปรแกรมไว้ใน the Guard Time register.
      TC ถูกบังคับ low ในระหว่างเวลานี้. เมื่อ the guard time counter ถึงค่าที่โปรแกรม TC ถูกถือสิทธ์ high.
•    การยกเลิกการถือสิทธ์ของ TC flag ไม่ได้รับผลกระทบจาก Smartcard mode.
•    ถ้า a framing error ถูกตรวจพบบน the transmitter end (เนื่องจาก a NACK จาก the receiver), the NACK จะไม่ถูกตรวจพบ
      เป็น a start bit โดยที่ the receive จะบล็อกการส่ง. สอดคล้องกันกับ the ISO protocol, ในระหว่างของ the received NACK
      สามารถเป็น 1 or 2 baud clock periods.
•    บน the receiver side, ถ้า a parity error ถูกตรวจพบและ a NACK ถูกส่ง the receiver จะไม่ตรวจพบ the NACK เป็น a start
      bit.

Note: A break character ไม่มีนัยสำคัญใน Smartcard mode. A 0x00 data พร้อมด้วย a framing error จะถูกถือว่าเป็น data
           และไม่ถือว่าเป็น a break.

           ไม่มี IDLE frame ถูกส่งเมื่อสลับ the TE bit. The IDLE frame (ดังที่กำหนดสำหรับ the other configurations) ไม่ถูก
           กำหนดโดย the ISO protocol.
Title: Re: STM32F1 USART
Post by: tha on January 23, 2021, 10:37:21 AM
Figure 294 รายละเอียดว่า the NACK signal ถูกสุ่มโดย the USART อย่างไร. ในตัวอย่างนี้, the USART ส่ง a data และถูกกำหนดค่าด้วย 1.5 stop bits. The receiver part ของ the USART ถูก enabled เพื่อเช็คความสมบูรณ์ของ the data and the NACK signal

(https://i.imgur.com/al2aWZj.png)

The USART สามารถจัดให้มี a clock ไปยัง the smartcard ผ่านทาง the CK output. ใน Smartcard mode, CK ไม่เกี่ยวข้องกับ the communication แต่ได้มาง่ายๆจาก the internal peripheral input clock ผ่านทาง a 5-bit prescaler. The division ratio ถูกกำหนดค่าใน the prescaler register USART_GTPR. CK frequency สามารถถูกโปรแกรมจาก fCK/2 ถึง fCK/62, ที่ fCK คือ the peripheral input clock.
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 07:11:11 AM
27.3.12 IrDA SIR ENDEC block

The IrDA mode ถูกเลือกโดยการเซ็ต the IREN bit in the USART_CR3 register. ใน IrDA mode, บิตต่อไปนี้ต้องถูกเก็บไว้ที่เคลียร์:
•    LINEN, STOP and CLKEN bits in the USART_CR2 register,
•    SCEN and HDSEL bits in the USART_CR3 register.

The IrDA SIR physical layer ระบุการใช้ a Return to Zero, Inverted (RZI) modulation แบบแผนที่แสดงลอจิก 0 เป็น an infrared light pulse (see Figure 295).

The SIR Transmit encoder จะปรับเปลี่ยน(modulates) the Non Return to Zero (NRZ) transmit bit stream output จาก USART. The output pulse stream ถูกส่งไปยัง an external output driver และ infrared LED. USART รองรับเฉพาะ bit rates สูงถึง 115.2Kbps สำหรับ the SIR ENDEC. ในโหมดปกติ the transmitted pulse width ถูกระบุเป็น 3/16 of a bit period.

The SIR receive decoder demodulates(ปรับคืนมาอย่างเดิม) the return-to-zero bit ไหลจาก the infrared detector และส่งออก the received NRZ serial bit ไหลไปยัง USART. The decoder input เป็นปกติ HIGH (marking state) ใน the idle state. The transmit encoder output มีขั้วตรงข้ามกับ the decoder input. A start bit ถูกตรวจพบเมื่อ the decoder input เป็น low.
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 07:53:15 AM
•    IrDA คือ a half duplex communication protocol. ถ้า the Transmitter กำลังยุ่งอยู่ (ตัวอย่างเช่น the USART ส่ง data ไป
      ยัง the IrDA encoder), data ใดๆบน the IrDA receive line ถูกเพิกเฉยโดย the IrDA decoder และถ้า the Receiver กำลัง
      ยุ่งอยู่ (USART รับ decoded data จาก the USART), data บน the TX จาก the USART ไปยัง IrDA ไม่ถูกเข้าระหัสโดย IrDA.
      ขณะ receiving data, transmission ควรถูกหลีกเลี่ยงดังที่ the data ที่ถูกส่งอาจเสียหาย.
•    A '0' ถูกส่งเป็น a high pulse และ a '1' ถูกส่งเป็น a '0'. ความกว้างของ the pulse ถูกระบุเป็น 3/16th ของ the selected bit
      period ใน normal mode (see Figure 296).
•    The SIR decoder กลับ the IrDA compliant receive signal ลงใน a bit stream สำหรับ USART.
•    The SIR receive logic ตีความ a high state เป็น a logic one และ low pulses เป็น logic zeros.
•    The transmit encoder output มีขั้วตรงข้ามกับ the decoder input. The SIR output อยู่ใน low state เมื่อ idle.
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 08:17:07 AM
•    The IrDA specification ต้องการการยอมรับของ pulses ที่มากกว่า 1.41 us. The acceptable pulse width สามารภโปรแกรมได้.
      Glitch detection ลอจิกบน the receiver end กรองออก pulses of width ที่น้อยกวา 2 PSC periods (PSC is the prescaler
      value ถูกโปรแกรมใน the IrDA low-power Baud Register, USART_GTPR). Pulses of width ที่น้อยกว่า 1 PSC period จะถูก
      โละทิ้งเสมอ, แต่ความกว้างเหล่านี้ที่มากกว่าหนึ่งและน้อยกว่าสองคาบเวลาอาจถูกยอมรับหรือถูกโละทิ้ง, พวกที่มากกว่า 2 periods จะถูก
      ยอมรับว่าเป็น a pulse. The IrDA encoder/decoder ไม่ทำงานเมื่อ PSC=0.
•    The receiver สามารถสื่อสารกับ a low-power transmitter.
•    In IrDA mode, the STOP bits in the USART_CR2 register ต้องถูกกำหนดค่าเป็น "1 stop bit".
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 09:10:13 AM
IrDA low-power mode

Transmitter

In low-power mode the pulse width ไม่ถูกเก็บไว้ที่ 3/16 ของ the bit period. แทน, the width of the pulse เป็น 3 เท่าของ the low-power baud rate ซึ่งสามารถต่ำสุดที่ 1.42 MHz.
คานี้โดยทั่วไปคือ 1.8432 MHz (1.42 MHz < PSC< 2.12 MHz). A low-power mode programmable divisor หาร the system clock เพื่อให้ได้ค่านี้.

Receiver

Receiving in low-power mode ก็คล้ายกันกับ receiving in normal mode. สำหรับ glitch detection, the USART ควรทิ้ง pulses of duration ที่สั้นกว่า 1/PSC. A valid low ถูกยอมรับเฉพาะถ้าระยะเวลาของมันมากกว่า 2 periods of the IrDA low-power Baud clock (PSC value in USART_GTPR).

Note: A pulse of width น้อยกว่าสองและมากกว่าหนึ่ง PSC period(s) อาจจะโละทิ้งหรือไม่โละทิ้ง.

           The receiver set up time ควรถูกจัดการโดย software. The IrDA physical layer specification ระบุค่าต่ำสุดที่ 10 ms
           หน่วงเวลาระหว่าง transmission and reception (IrDA คือ a half duplex protocol).

(https://i.imgur.com/riDRvLm.png)
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 11:23:15 AM
27.3.13 Continuous communication using DMA

The USART มีความสามารถของการสื่อสารอย่างต่อเนื่องโดยใช้ the DMA. The DMA requests สำหรับ Rx buffer and Tx buffer ถูกสร้างขึ้นโดยอิสระ.

Note: ผู้ใช้ควรอ้างอิงถึง product specs สำหรับการมีให้ใช้ของ the DMA controller. ถ้า DMA ไม่มีให้ใช้ใน the product, คุณควรใช้
           the USART ดังอธิบายใน Section 27.3.2 or 27.3.3. ใน the

USART_SR register, ผู้ใช้สามารถเคลียร์ the TXE/ RXNE flags เพื่อให้สำเร็จ continuous communication.

Transmission using DMA

DMA mode สามารถถูก enabled สำหรับ transmission โดยการเซ็ต DMAT bit in the USART_CR3 register. Data ถูกโหลดจาก a SRAM area ที่กำหนดค่าโดยใช้ the DMA peripheral (อ้างอิงถึง the DMA specification) ไปยัง the USART_DR register เมื่อไรก็ตามที่ the TXE bit ถูก set. เพื่อแม็ป a DMA channel สำหรับ USART transmission, ใช้ขั้นตอนดังต่อไปนี้ (x หมายถึง the
channel number):
1.    เขียน the USART_DR register address ใน the DMA control register เพื่อกำหนดค่ามันเป็นปลายทางของ the transfer.
       The data จะถูกย้ายไปยัง address นี้จาก memory หลังจากแต่ละ TXE event
2.    เขียน the memory address ใน the DMA control register เพื่อกำหนดค่ามันเป็นต้นทางของ the transfer. The data จะถูก
       โหลดลงใน the USART_DR register จาก memory area นี้หลังจากแต่ละ TXE event.
3.    กำหนดค่าจำนวนทั้งหมดของ bytes ที่จะถูกส่งถ่ายลงใน the DMA control register.
4.    กำหนดค่า the channel priority ใน the DMA register
5.    กำหนดค่า DMA interrupt generation หลังจาก half/ full transfer ตามที่ต้องการโดย the application.
6.    เคลียร์ the TC bit in the SR register โดยการเขียน 0 ไปยังมัน.
7.    ทำให้ทำงาน the channel in the DMA register

เมื่อจำนวนของ data transfers ที่โปรแกรมใน the DMA Controller ถูกถึง, the DMA controller จะสร้าง an interrupt บน the DMA channel interrupt vector

ใน transmission mode, เมื่อ the DMA ได้เขียนทุก the data ที่จะถูกส่งหมดแล้ว (the TCIF flag ถูก set ใน the DMA_ISR register), the TC flag สามารถถูกเฝ้ามองเพื่อให้แน่ใจว่า the USART communication เสร็จสมบูรณ์. นี้ถูกต้องการเพื่อหลีกเลี่ยงการเสียหาย the last transmission ก่อนปิดการใช้งาน the USART หรือเข้าสู่ the Stop mode. The software ต้องคอยจนกระทั่ง TC=1. The TC flag ยังคงถูกเคลียร์ในระหว่างทุก data transfers และมันถูกเซ็ตโดย hardware เมื่อสิ้นสุดการส่งเฟรมสุดท้าย

(https://i.imgur.com/BuP40dU.png)
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 12:22:58 PM
Reception using DMA

DMA mode สามารถถูก enabled สำหรับ reception โดยการเซ็ต the DMAR bit in USART_CR3 register. Data ถูกโหลดจาก the USART_DR register ไปยัง a SRAM area ที่กำหนดค่าโดยใช้ the DMA peripheral (refer to the DMA specification) เมื่อไรก็ตามที่ a data byte ถูกรับ. เพื่อแม็ป a DMA channel สำหรับ USART reception, ใช้ขั้นตอนดังต่อไปนี้:
1.    เขียน the USART_DR register address ใน the DMA control register เพื่อกำหนดค่ามันเป็นต้นทางของ the transfer. The
       data จะถูกย้ายจาก address นี้ไปยัง the memory หลังจากแต่ละ RXNE event.
2.    เขียน the memory address ใน the DMA control register เพื่อกำหนดค่ามันเป็นปลายทางของ the transfer. The data จะ
       ถูกโหลดจาก the USART_DR register ไปยัง memory area นี้หลังจากแต่ละ RXNE event.
3.    กำหนดค่าจำนวนทั้งหมดของ bytes ที่จะถูกส่งถ่ายลงใน the DMA control register.
4.    กำหนดค่า the channel priority ใน the DMA register
5.    กำหนดค่า DMA interrupt generation หลังจาก half/ full transfer ตามที่ต้องการโดย the application.
6.    ทำให้ทำงาน the channel in the DMA register

เมื่อจำนวนของ data transfers ที่โปรแกรมใน the DMA Controller ถูกถึง, the DMA controller จะสร้าง an interrupt บน the DMA channel interrupt vector

(https://i.imgur.com/6bh1HAi.png)
Title: Re: STM32F1 USART
Post by: tha on January 24, 2021, 12:34:17 PM
Error flagging and interrupt generation in multibuffer communication

ในกรณีของ multibuffer communication ถ้า error ใดๆเกิดขึ้นในระหว่างการติดต่อกัน the error flag จะถูกถือสิทธิ์หลังจาก the current byte. An interrupt จะถูกสร้างขึ้นถ้า the interrupt enable flag ถูก set. สำหรับ framing error, overrun error and noise flag ซึ่งถูกถือสิทธิ์พร้อมกับ RXNE ในกรณีของ single byte reception, จะมี separate error flag interrupt enable bit (EIE bit in the USART_CR3 register), ซึ่งถ้า set จะปล่อยออก an interrupt หลังจาก the current byte พร้อมกับอย่างใดอย่างหนึ่งของ errors เหล่านี้.

Title: Re: STM32F1 USART
Post by: tha on January 25, 2021, 07:08:40 AM
27.3.14 Hardware flow control

มันเป็นไปได้ที่จะควบคุม the serial data flow ระหว่าง two devices โดยการใช้ the CTS input และ the RTS output. Figure 299 แสดงวิธีการต่อ two devices ในโหมดนี้:

(https://i.imgur.com/k282m4L.png)

RTS and CTS flow control สามารถถูก enabled อย่างอิสระโดยการเขียน RTSE and CTSE bits เป็น 1 ตามลำดับ (ใน the USART_CR3 register).

RTS flow control

ถ้า the RTS flow control ถูก enabled (RTSE=1), จากนั้น RTS ถูกถือสิทธิ์ (tied low) ตราบเท่าที่ the USART receiver พร้อมที่จะรับ new data. เมื่อ the receive register เต็ม, RTS ยกเลิกการถือสิทธิ์, แสดงให้เห็นว่า the transmission คาดว่าจะหยุดที่ the end of the current frame. Figure 300 แสดงตัวอย่างของ communication พร้อมกับ RTS flow control ถูกเปิดการใช้งาน.

(https://i.imgur.com/lMywGZx.png)

CTS flow control

ถ้า the CTS flow control ถูก enabled (CTSE=1), จากนั้น the transmitter เช็ค the CTS input ก่อนการส่ง the next frame. ถ้า CTS ถูกถือสิทธิ์ (tied low), จากนั้น the next data ถูกส่ง (สมมุติว่า a data จะถูกส่ง, กล่าวอีกนัยหนึ่ง, ถ้า TXE=0), ถ้าเป็นอย่างอื่น the transmission จะไม่เกิดขึ้น. เมื่อ CTS ถูกยกเลิกการถือสิทธิ์ในระหว่าง a transmission, the current transmission เสร็จสมบูรณ์ก่อนที่ the transmitter จะหยุด.

เมื่อ CTSE=1, the CTSIF status bit ถูกเซ็ตโดยอัตโนมัติโดย hardware ทันทีที่ the CTS input สลับ. มันแสดงให้เห็นว่าเมื่อ the receiver กลายมาเป็นพร้อมหรือไม่พร้อมสำหรับ communication. An interrupt ถูกสร้างขึ้นถ้า the CTSIE bit ใน the USART_CR3 register ถูกเซ็ต. รูปภายข้างล่างแสดงตัวอย่างของ communication พร้อมกับ CTS flow control ถูกเปิดการใช้งาน.

(https://i.imgur.com/wrNm1b5.png)
Title: Re: STM32F1 USART
Post by: tha on January 25, 2021, 08:55:02 AM
27.4 USART interrupts

(https://i.imgur.com/qqfsmii.png)

The USART interrupt events ถูกต่อถึง the same interrupt vector (see Figure 302).
•    ในระหว่าง transmission: Transmission Complete, Clear to Send or Transmit Data Register empty interrupt.
•    ในขณะที่ receiving: Idle Line detection, Overrun error, Receive Data register not empty, Parity error, LIN break
      detection, Noise Flag (only in multi buffer communication) and Framing Error (only in multi buffer
      communication).

events เหล่านี้สร้าง an interrupt ถ้า the corresponding Enable Control Bit ถูก set.

(https://i.imgur.com/Av5JCVE.png)
Title: Re: STM32F1 USART
Post by: tha on January 25, 2021, 09:04:35 AM
27.5 USART mode configuration

(https://i.imgur.com/1vBL4TL.png)
Title: Re: STM32F1 USART
Post by: tha on January 26, 2021, 07:38:53 AM
27.6 USART registers

อ้างอิงถึง Section 2.2 on page 45 สำหรับรายการของตัวย่อที่ใช้ใน register descriptions.

The peripheral registers สามารถถูกเข้าถึงโดย half-words (16-bit) or words (32-bit).

(https://i.imgur.com/jjqDlUE.png)

Bits 31:10 Reserved, forced by hardware to 0.

Bit 9 CTS: CTS flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ the CTS input สลับ, ถ้า the CTSE bit ถูกเซ็ต. มันถูกเคลียร์โดย software (โดยการเขียนมันเป็น 0). An interrupt ถูกสร้างขึ้นถ้า CTSIE=1 in the USART_CR3 register.
     0: ไม่มีการเปลี่ยนแปลงเกิดขึ้นบน the CTS status line
     1: การเปลี่ยนแปลงเกิดขึ้นบน the CTS status line
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 8 LBD: LIN break detection flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ the LIN break ถูกตรวจพบ. มันถูกเคลียร์โดย software (โดยการเขียนมันเป็น 0). An interrupt ถูกสร้างขึ้นถ้า LBDIE = 1 in the USART_CR2 register.
     0: LIN Break ไม่ถูกตรวจพบ
     1: LIN break ถูกตรวจพบ
Note: An interrupt ถูกสร้างขึ้นเมื่อ LBD=1 ถ้า LBDIE=1

Bit 7 TXE: Transmit data register empty
บิตนี้ถูกเซ็ตโดย hardware เมื่อสิ่งที่บรรจุของ the TDR register ถูกส่งถ่ายลงใน the shift register. An interrupt ถูกสร้างขึ้นถ้า the TXEIE bit =1 in the USART_CR1 register. มันถูกเคลียร์โดยการเขียนไปยัง the USART_DR register.
     0: Data ไม่ถูกส่งถ่ายไปยัง the shift register
     1: Data ถูกส่งถ่ายไปยัง the shift register)
Note: บิตนี้ถูกใช้ในระหว่าง single buffer transmission.

Bit 6 TC: Transmission complete
บิตนี้ถูกเซ็ตโดย hardware ถ้า the transmission ของ a frame ที่บรรจุ data เสร็จสมบูรณ์และถ้า TXE ถูกเซ็ต. An interrupt ถูกสร้างขึ้นถ้า TCIE=1 in the USART_CR1 register. มันถูกเคลียร์โดย a software sequence (การอ่านจาก the USART_SR register ตามด้วยการเขียนไปยัง the USART_DR register). The TC bit สามารถถูกเคลียร์โดยการเขียน a '0' ไปยังมัน. ลำดับการเคลียร์นี้ขอแนะนำให้ใช้เฉพาะสำหรับ multibuffer communication.
     0: Transmission ไม่เสร็จสมบูรณ์
     1: Transmission เสร็จสมบูรณ์

Bit 5 RXNE: Read data register not empty
บิตนี้ถูกเซ็ตโดย hardware เมื่อสิ่งที่บรรจุของ the RDR shift register ถูกส่งถ่ายไปยัง the USART_DR register. An interrupt ถูกสร้างขึ้นถ้า RXNEIE=1 in the USART_CR1 register. มันถูกเคลียร์โดยการอ่านไปยัง the USART_DR register. The RXNE flag สามารถถูกเคลียร์โดยการเขียนศูนย์ไปยังมันได้อีกด้วย. ลำดับการเคลียร์นี้ขอแนะนำให้ใช้เฉพาะสำหรับ multibuffer communication.
     0: Data ไม่ถูกรับ
     1: Received data พร้อมที่จะถูกอ่าน.

Bit 4 IDLE: IDLE line detected
บิตนี้ถูกเซ็ตโดย hardware เมื่อ an Idle Line ถูกตรวจพบ. An interrupt ถูกสร้างขึ้นถ้า the IDLEIE=1 in the USART_CR1 register. มันถูกเคลียร์โดย a software sequence (การอ่านไปยัง the USART_SR register ตามด้วยการอ่านไปยัง the USART_DR register).
     0: ไม่มี Idle Line ถูกตรวจพบ
     1: Idle Line ถูกตรวจพบ
Note: The IDLE bit จะไม่ถูกเซ็ตอีกครั้งจนกระทั่ง the RXNE bit ถูกเซ็ตด้วยตัวมันเอง (อย่างเช่น a new idle line เกิดขึ้น).
Title: Re: STM32F1 USART
Post by: tha on January 26, 2021, 09:26:28 AM
Bit 3 ORE: Overrun error
บิตนี้ถูกเซ็ตโดย hardware เมื่อ the word ที่ปัจจุบันกำลังถูกรับใน the shift register พร้อมที่จะถูกส่งถ่ายลงใน the RDR register ในขณะที่ RXNE=1. An interrupt ถูกสร้างขึ้นถ้า RXNEIE=1 in the USART_CR1 register. มันถูกเคลียร์โดย a software sequence (การอ่านไปยัง the USART_SR register ตามด้วยการอ่านไปยัง the USART_DR register).
     0: ไม่มี Overrun error
     1: Overrun error ถูกตรวจพบ
Note: เมื่อบิตนี้ถูกเซ็ต, the RDR register content จะไม่ถูกทำให้สูญหายแต่ the shift register จะถูกเขียนทับ. An interrupt ถูก
           สร้างขึ้นบน ORE flag ในกรณีของ Multi Buffer communication ถ้า the EIE bit ถูก set.

Bit 2 NE: Noise error flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ noise ถูกตรวจพบบน a received frame. มันถูกเคลียร์โดย a software sequence (การอ่านไปยัง the USART_SR register ตามด้วยการอ่านไปยัง the USART_DR register).
     0: ไม่มี noise ถูกตรวจพบ
     1: Noise ถูกตรวจพบ
Note: บิตนี้ไม่สร้าง interrupt เนื่องจากมันปรากฎในเวลาเดียวกันกับ the RXNE bit ซึ่งตัวมันเองสร้างการอินเตอรัพท์ interrupt ถูกสร้าง
           ขึ้นบน NE flag ในกรณีของ Multi Buffer communication ถ้า the EIE bit ถูก set.

Bit 1 FE: Framing error
บิตนี้ถูกเซ็ตโดย hardware เมื่อ a de-synchronization, excessive noise or a break character ถูกตรวจพบ. มันถูกเคลียร์โดย a software sequence (การอ่านไปยัง the USART_SR register ตามด้วยการอ่านไปยัง the USART_DR register).
     0: ไม่มี Framing error ถูกตรวจพบ
     1: Framing error or break character ถูกตรวจพบ
Note: บิตนี้ไม่สร้าง interrupt เนื่องจากมันปรากฎในเวลาเดียวกันกับ the RXNE bit ซึ่งตัวมันเองสร้าง an interrupt. ถ้า the word ที่
           ปัจจุบันกำลังถูกส่งถ่ายเป็นสาเหตุทั้ง frame error and overrun error, มันจะถูกส่งถ่ายและเฉพาะ the ORE bit จะถูกเซ็ต. An
           interrupt ถูกสร้างขึ้นบน FE flag ในกรณีของ Multi Buffer communication ถ้า the EIE bit ถูก set.

Bit 0 PE: Parity error
บิตนี้ถูกเซ็ตโดย hardware เมื่อ a parity error เกิดขึ้นใน receiver mode. มันถูกเคลียร์โดย a software sequence (การอ่านไปยัง the USART_SR register ตามด้วยการอ่านไปยัง the USART_DR register). The software ต้องคอยสำหรับ the RXNE flag ถูกเซ็ตก่อนการเคลียร์ the PE bit. An interrupt ถูกสร้างขึ้นถ้า PEIE = 1 in the USART_CR1 register.
     0: No parity error
     1: Parity error
Title: Re: STM32F1 USART
Post by: tha on January 26, 2021, 10:38:55 AM
(https://i.imgur.com/1tBai9n.png)

Bits 31:9 Reserved, forced by hardware to 0.

Bits 8:0 DR[8:0]: Data value
บรรจุ the Received or Transmitted data character, ขึ้นอยู่กับว่ามันถูกอ่านจากหรือเขียนถึง.
The Data register ทำหน้าที่ a double function (read and write) เนื่องจากมันประกอบด้วย two registers, one for transmission (TDR) and one for reception (RDR)
The TDR register จัดให้มี the parallel interface ระหว่าง the internal bus และ the output shift register (see Figure 1).
The RDR register จัดให้มี the parallel interface ระหว่าง the input shift register และ the internal bus.
เมื่อการส่งพร้อมด้วย the parity ถูกเปิดการใช้งาน (PCE bit ถูกเซ็ตเป็น 1 ใน the USART_CR1 register), ค่าที่ถูกเขียนใน the MSB (bit 7 หรือ bit 8 ขึ้นอยู่กับ the data length) จะไม่มีผลเพราะมันถูกแทนที่โดย the parity.
เมื่อการรับพร้อมด้วย the parity ถูกเปิดการใช้งาน, ค่าที่ถูกอ่านใน the MSB bit คือ the received parity bit.
Title: Re: STM32F1 USART
Post by: tha on January 26, 2021, 11:10:52 AM
27.6.3 Baud rate register (USART_BRR)

Note: The baud counters หยุดการนับถ้า the TE or RE bits ถูกปิดการใช้งานตามลำดับ.

Address offset: 0x08

Reset value: 0x0000

(https://i.imgur.com/8u6jjdx.png)

Bits 31:16 Reserved, forced by hardware to 0.

Bits 15:4 DIV_Mantissa[11:0]: mantissa of USARTDIV
12 bits เหล่านี้กำหนดตัวเลขด้านขวาของจุดของ the USART Divider (USARTDIV)

Bits 3:0 DIV_Fraction[3:0]: fraction of USARTDIV
4 bits เหล่านี้กำหนดเศษส่วนของ the USART Divider (USARTDIV)
Title: Re: STM32F1 USART
Post by: tha on January 27, 2021, 07:00:09 AM
(https://i.imgur.com/FUKqa1K.png)

Bits 31:14 Reserved, forced by hardware to 0.

Bit 13 UE: USART enable
เมื่อบิตนี้ถูกเคลียร์ the USART prescalers และ outputs ถูกหยุดและสิ้นสุดของ the current byte transfer เพื่อที่จะลด power consumption. บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: USART prescaler และ outputs ถูกปิดการใช้งาน
     1: USART ถูกเปิดการใช้งาน

Bit 12 M: Word length
บิตนี้ตัดสิน the word length. มันถูกเซ็ตและเคลียร์โดย software.
     0: 1 Start bit, 8 Data bits, n Stop bit
     1: 1 Start bit, 9 Data bits, n Stop bit
Note: The M bit ต้องไม่ถูกแก้ไขในระหว่าง a data transfer (ทั้ง transmission and reception)

Bit 11 WAKE: Wakeup method
บิตนี้ตัดสิน the USART wakeup method. มันถูกเซ็ตและเคลียร์โดย software.
     0: Idle Line
     1: Address Mark

Bit 10 PCE: Parity control enable
บิตนี้เลือก the hardware parity control (generation and detection). เมื่อ the parity control ถูกเปิดการใช้งาน, the computed parity ถูกใส่ที่ the MSB position (9th bit ถ้า M=1; 8th bit ถ้า M=0) และ parity ถูกเช็คบน the received data. บิตนี้ถูกเซ็ตและเคลียร์โดย software. เมื่อมันถูกเซ็ต, PCE จะทำงานหลังจาก the current byte (ใน reception และใน transmission).
     0: Parity control ถูกปิดการใช้งาน
     1: Parity control ถูกเปิดการใช้งาน

Bit 9 PS: Parity selection
บิตนี้เลือก the odd or even parity เมื่อ the parity generation/detection ถูกเปิดการใช้งาน (PCE bit set). มันถูกเซ็ตและเคลียร์โดย software. The parity จะถูกเลือกหลังจาก the current byte.
     0: Even parity
     1: Odd parity

Bit 8 PEIE: PE interrupt enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: Interrupt ถูกยับยั้ง
     1: A USART interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ PE=1 in the USART_SR register

Bit 7 TXEIE: TXE interrupt enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: Interrupt ถูกยับยั้ง
     1: A USART interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ TXE=1 in the USART_SR register

Bit 6 TCIE: Transmission complete interrupt enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: Interrupt ถูกยับยั้ง
     1: A USART interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ TC=1 in the USART_SR register

Bit 5 RXNEIE: RXNE interrupt enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: Interrupt ถูกยับยั้ง
     1: A USART interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ ORE=1 or RXNE=1 in the USART_SR register

Bit 4 IDLEIE: IDLE interrupt enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: Interrupt ถูกยับยั้ง
     1: A USART interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ IDLE=1 in the USART_SR register
Title: Re: STM32F1 USART
Post by: tha on January 27, 2021, 08:25:40 AM
Bit 3 TE: Transmitter enable
บิตนี้เปิดการใช้งาน the transmitter. มันถูกเซ็ตและเคลียร์โดย software.
     0: Transmitter ถูกปิดการใช้งาน
     1: Transmitter ถูกเปิดการใช้งาน
Note: 1: ในระหว่าง transmission, a "0" pulse บน the TE bit ("0" ตามด้วย "1") ส่ง a preamble (idle line) หลังจาก the
               current word, ยกเว้นใน Smartcard mode.
           2: เมื่อ TE ถูกเซ็ตจะมี a 1 bit-time delay ก่อน the transmission starts.

Bit 2 RE: Receiver enable
บิตนี้เปิดการใช้งาน the receiver. มันถูกเซ็ตและเคลียร์โดย software.
     0: Receiver ถูกปิดการใช้งาน
     1: Receiver ถูกเปิดการใช้งานและเริ่มต้นการค้นหาสำหรับ a start bit

Bit 1 RWU: Receiver wakeup
บิตนี้ตัดสินถ้า the USART อยู่ใน mute mode หรือไม่. มันถูกเซ็ตและเคลียร์โดย software และสามารถถูกเคลียร์โดย hardware เมื่อ a wakeup sequence ถูกจำได้.
     0: Receiver in active mode
     1: Receiver in mute mode
Note: 1: ก่อนการเลือก Mute mode (โดยการเซ็ต the RWU bit) the USART ต้องรับ a data byte เป็นอันดับแรก, มิฉะนั้นมันไม่
               สามารถทำหน้าที่ใน Mute mode พร้อมด้วย wakeup โดย Idle line detection.
           2: ใน Address Mark Detection wakeup configuration (WAKE bit=1) the RWU bit ไม่สามารถถูกแก้ไขโดย
               software ในขณะที่ the RXNE bit ถูก set.

Bit 0 SBK: Send break
บิตนี้เซ็ตถูกใช้เพื่อส่ง break characters. มันสามารถถูกเซ็ตและเคลียร์โดย software. มันควรถูกเซ็ตโดย software, และจะถูก reset โดย hardware ในระหว่าง the stop bit of break.
     0: ไม่มี break character ถูกส่ง
     1: Break character จะถูกส่ง
Title: Re: STM32F1 USART
Post by: tha on January 27, 2021, 10:01:21 AM
(https://i.imgur.com/Dd45PwU.png)

Bits 31:15 Reserved, forced by hardware to 0.

Bit 14 LINEN: LIN mode enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: LIN mode disabled
     1: LIN mode enabled
The LIN mode เปิดการใช้งาน the capability เพื่อส่ง LIN Synch Breaks (13 low bits) โดยใช้ the SBK bit ใน the USART_CR1 register, และเพื่อตรวจจับ LIN Sync breaks.

Bits 13:12 STOP: STOP bits
บิตเหล่านี้ถูกใช้สำหรับการโปรแกรม the stop bits.
     00: 1 Stop bit
     01: 0.5 Stop bit
     10: 2 Stop bits
     11: 1.5 Stop bit
The 0.5 Stop bit and 1.5 Stop bit ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 11 CLKEN: Clock enable
บิตนี้ยอมให้ผู้ใช้เปิดการใช้งาน the CK pin.
     0: CK pin ถูกปิดการใช้งาน
     1: CK pin ถูกเปิดการใช้งาน
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 10 CPOL: Clock polarity
บิตนี้ยอมให้ผู้ใช้เลือก the polarity ของ the clock output บน the CK pin ใน synchronous mode. มันทำงานร่วมกันกับ the CPHA bit เพื่อผลิต the desired clock/data relationship
     0: Steady low value บน CK pin ภายนอก transmission window.
     1: Steady high value บน CK pin ภายนอก transmission window.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 9 CPHA: Clock phase
บิตนี้ยอมให้ผู้ใช้เลือก the phase ของ the clock output บน the CK pin ใน synchronous mode. มันทำงานร่วมกันกับ the CPOL bit เพื่อผลิต the desired clock/data relationship (see figures 290 to 291)
     0: The first clock transition คือ the first data capture edge.
     1: The second clock transition คือ the first data capture edge.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.
Title: Re: STM32F1 USART
Post by: tha on January 27, 2021, 11:17:16 AM
Bit 8 LBCL: Last bit clock pulse
บิตนี้ยอมให้ผู้ใช้เลือกว่า the clock pulse ที่เกี่ยวข้องกับ the last data bit transmitted (MSB) ต้องถูกส่งออกบน the CK pin in synchronous mode.
     0: The clock pulse of the last data bit ไม่ถูกส่งออกไปยัง the CK pin
     1: The clock pulse of the last data bit ถูกส่งออกไปยัง the CK pin
The last bit คือ the 8th or 9th data bit ที่ส่งขึ้นอยู่กับ the 8 or 9 bit format ที่เลือกโดย the M bit in the USART_CR1 register.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 7 Reserved, forced by hardware to 0.

Bit 6 LBDIE: LIN break detection interrupt enable
Break interrupt mask (break detection โดยใช้ break delimiter).
     0: Interrupt ถูกยับยั้ง
     1: An interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ LBD=1 in the USART_SR register

Bit 5 LBDL: lin break detection length
บิตนี้สำหรับการเลือกระหว่าง 11 bit or 10 bit break detection.
     0: 10 bit break detection
     1: 11 bit break detection

Bit 4 Reserved, forced by hardware to 0.

Bits 3:0 ADD[3:0]: Address of the USART node
     bit-field นี้ให้ the address of the USART node.
     นี้ถูกใช้ใน multiprocessor communication ในระหว่าง mute mode, สำหรับ wake up ด้วย address mark detection.

Note: These 3 bits (CPOL, CPHA, LBCL) ไม่ควรถูกเขียนในขณะ the transmitter ถูก enabled
Title: Re: STM32F1 USART
Post by: tha on January 28, 2021, 07:49:25 AM
(https://i.imgur.com/fEUXiPy.png)

Bits 31:11 Reserved, forced by hardware to 0.

Bit 10 CTSIE: CTS interrupt enable
     0: Interrupt ถูกยับยั้ง
     1: An interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ CTS=1 in the USART_SR register
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 9 CTSE: CTS enable
     0: CTS hardware flow control ถูกปิดการใช้งาน
     1: CTS mode enabled, data ถูกส่งเฉพาะเมื่อ the CTS input ถูกถือสิทธิ์ (ดึงเป็น 0). ถ้า the CTS input ถูกยกเลิกถือสิทธิ์ใน
         ขณะที่ a data กำลังถูกส่ง, จากนั้น the transmission ถูกทำให้เสร็จสมบูรณ์ก่อนการหยุด. ถ้า a data ถูกเขียนลงใน the data
         register ในขณะที่ CTS ถูกยกเลิกถือสิทธิ์, the transmission ถูกเลื่อนออกไปจนกระทั่ง CTS ถูกถือสิทธิ์
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 8 RTSE: RTS enable
     0: RTS hardware flow control ถูกปิดการใช้งาน
     1: RTS interrupt ถูกเปิดการใช้งาน, data ถูกร้องขอเฉพาะเมื่อมีพื้นที่ว่างใน the receive buffer. The transmission of data
         ถูกคาดว่าจะหยุดหลังจาก the current character ถูกส่งแล้ว. The RTS output ถูกถือสิทธิ์ (ดึงเป็น 0) เมื่อ a data สามารถถูก
         รับ.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 7 DMAT: DMA enable transmitter
บิตนี้ถูก set/reset โดย software
     1: DMA mode ถูกเปิดการใช้งานสำหรับ transmission
     0: DMA mode ถูกปิดการใช้งานสำหรับ transmission
บิตนี้ไม่มีให้ใช้สำหรับ UART5

Bit 6 DMAR: DMA enable receiver
บิตนี้ถูก set/reset โดย software
     1: DMA mode ถูกเปิดการใช้งานสำหรับ reception
     0: DMA mode ถูกปิดการใช้งานสำหรับ reception
บิตนี้ไม่มีให้ใช้สำหรับ UART5
Title: Re: STM32F1 USART
Post by: tha on January 28, 2021, 09:13:07 AM
Bit 5 SCEN: Smartcard mode enable
บิตนี้ถูกใช้สำหรับเปิดการใช้งาน Smartcard mode.
     0: Smartcard Mode ถูกปิดการใช้งาน
     1: Smartcard Mode ถูกเปิดการใช้งาน
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 4 NACK: Smartcard NACK enable
     0: NACK transmission ในกรณีของ parity error ถูกปิดการใช้งาน
     1: NACK transmission ในระหว่าง parity error ถูกเปิดการใช้งาน
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bit 3 HDSEL: Half-duplex selection
การเลือกของ Single-wire Half-duplex mode
     0: Half duplex mode ไม่ถูกเลือก
     1: Half duplex mode ถูกเลือก

Bit 2 IRLP: IrDA low-power
บิตนี้ถูกใช้สำหรับการเลือกระหว่าง normal and low-power IrDA modes
     0: Normal mode
     1: Low-power mode

Bit 1 IREN: IrDA mode enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software.
     0: IrDA ถูกปิดการใช้งาน
     1: IrDA ถูกเปิดการใช้งาน

Bit 0 EIE: Error interrupt enable
Error Interrupt Enable Bit ถูกต้องการเพื่อเปิดการใช้งาน interrupt generation ในกรณีของ a framing error, overrun error or noise error (FE=1 or ORE=1 or NE=1 in the USART_SR register) ในกรณีของ Multi Buffer Communication (DMAR=1 in the USART_CR3 register).
     0: Interrupt ถูกยับยั้ง
     1: An interrupt ถูกสร้างขึ้นเมื่อใดก็ตามที่ DMAR=1 in the USART_CR3 register and FE=1 or ORE=1 or NE=1 in the
         USART_SR register.
Title: Re: STM32F1 USART
Post by: tha on January 28, 2021, 10:58:40 AM
(https://i.imgur.com/rIaj1ie.png)

Bits 31:16 Reserved, forced by hardware to 0.

Bits 15:8 GT[7:0]: Guard time value
bit-field นี้ให้ the Guard time value ในเทอมของจำนวนของ baud clocks.
นี้ถูกใช้ใน Smartcard mode. The Transmission Complete flag ถูกเซ็ตหลังจาก guard time value นี้.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.

Bits 7:0 PSC[7:0]: Prescaler value
– In IrDA Low-power mode:
PSC[7:0] = IrDA Low-Power Baud Rate
ถูกใช้สำหรับการโปรแกรม the prescaler เพื่อการหาร the system clock ให้ประสบผลสำเร็จ the low-power frequency:
The source clock ถูกหารโดยค่าที่ให้ไว้ใน the register นี้ (8 significant bits):
     00000000: สงวนไว้ - ห้ามโปรแกรมค่านี้
     00000001: หาร the source clock ด้วย 1
     00000010: หาร the source clock ด้วย 2

– In normal IrDA mode: PSC ต้องถูกเซ็ตเป็น 00000001.
– In Smartcard mode:
PSC[4:0]: Prescaler value
ถูกใช้สำหรับการโปรแกรม the prescaler เพื่อการหาร the system clock เพื่อจัดให้มี the smartcard clock.
ค่านี้ถูกให้ไว้ใน the register (5 significant bits) ถูกคูณด้วย 2 เพื่อให้ the division factor of the source clock frequency:
     00000: สงวนไว้ - ห้ามโปรแกรมค่านี้
     00001: หาร the source clock ด้วย 2
     00010: หาร the source clock ด้วย 4
     00011: หาร the source clock ด้วย 6

Note: Bits [7:5] ไม่มีผลอะไรถ้า Smartcard mode ถูกใช้.
บิตนี้ไม่มีให้ใช้สำหรับ UART4 & UART5.
Title: Re: STM32F1 USART
Post by: tha on January 28, 2021, 11:02:06 AM
(https://i.imgur.com/rz2OTXz.png)