STM32F1 USART

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

Previous topic - Next topic

tha

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.

tha

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.



tha

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.



tha

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.



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.

tha

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.




tha

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 เสมอ).





Note: หน้าที่ของ CK แตกต่างไปใน Smartcard mode. อ้างอิงถึง the Smartcard mode section for more details.

tha

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.

tha

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.



เมื่อถูกต่อถึง a smartcard, the USART TX output ขับ a bidirectional line ที่ถูกขับโดย the smartcard ได้อีกด้วย. The TX pin ต้องถูกกำหนดค่าเป็น open drain.