STM32F1 USART

Started by tha, January 16, 2021, 07:14:07 AM

Previous topic - Next topic

tha

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 จะไม่ถูกส่ง.

tha

•    การถือสิทธิ์ของ 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.

tha

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



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.


tha

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.

tha

•    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.

tha

•    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".

tha

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).


tha

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 เมื่อสิ้นสุดการส่งเฟรมสุดท้าย