본문 바로가기
임베디드.일렉트로닉스/STM32

STM32L4x6. USART

by i.got.it 2018. 12. 10.

 

개요. STM32L4x6 USART

 

 3개의 USART : USART1, USART2, USART3
 2개의 UART : UART4, UART5.
 1개의 LPUART : LPUART1.


USART main features

• Full-duplex asynchronous communications
• NRZ standard format (mark/space)
• Configurable oversampling method by 16 or 8 to give flexibility between speed and
clock tolerance
• A common programmable transmit and receive baud rate of up to 10 Mbit/s when the
clock frequency is 80 MHz and oversampling is by 8
• Dual clock domain allowing:
– USART functionality and wakeup from Stop mode
– Convenient baud rate programming independent from the PCLK reprogramming
• Auto baud rate detection
• Programmable data word length (7, 8 or 9 bits)
• Programmable data order with MSB-first or LSB-first shifting
• Configurable stop bits (1 or 2 stop bits)
• Synchronous mode and clock output for synchronous communications
• Single-wire Half-duplex communications
• Continuous communications using DMA
• Received/transmitted bytes are buffered in reserved SRAM using centralized DMA
• Separate enable bits for transmitter and receiver
• Separate signal polarity control for transmission and reception
• Swappable Tx/Rx pin configuration
• Hardware flow control for modem and RS-485 transceiver
• Communication control/error detection flags
• Parity control:
– Transmits parity bit
– Checks parity of received data byte
• Fourteen interrupt sources with flags
• Multiprocessor communications
The USART enters mute mode if the address does not match.
• Wakeup from mute mode (by idle line detection or address mark detection)

USART extended features

• LIN master synchronous break send capability and LIN slave break detection capability
– 13-bit break generation and 10/11-bit break detection when USART is hardware
configured for LIN
• IrDA SIR encoder decoder supporting 3/16 bit duration for normal mode
• Smartcard mode
– Supports the T=0 and T=1 asynchronous protocols for smartcards as defined in
the ISO/IEC 7816-3 standard
– 0.5 and 1.5 stop bits for smartcard operation
• Support for ModBus communication
– Timeout feature
– CR/LF character recognition







 


 

 

USART Block Diagram

   


 


 

 

USART Transmitter

 

1. TE (Transmit Enable bit, register USART_CR1) must be set in order to activate the transmiter function.
2. USART 송신중에는 Transmit Shift Register 의 비트를 LSB 부터 TX핀으로 출력하게 된다.
3. register USART_TDR 이 내부버스와 Transmit Shift Register 사이의 버퍼 역할을 한다.
4. USART_TDR 에 데이터 기록하기 전에 TE bit 이 반드시 셋되어있어야 한다.
5. 데이터 송신중에는 TE bit 리셋하면 정상적인 송신 안된다.

송신 절차
1. TE bit set.
2. USART_TDR 에 데이터 기록한다. 기록하면 TXE bit 가 clear 됨.
3. USART_TDR 에 마지막 바이트 기록하고나서, TC bit (register USART_ISR) = 1 이 될때까지 대기. 마지막 프레임 송신 완료되었음 의미.

TXE bit.
1. USART_TDR에 쓰기 하면 TXE는 항상 reset 된다.
2. TXE 가 다시 하드웨어 셋되는 시점은 USART_TDR 의 데이터가 shift register로 이전되었을때.
- TXE = 1 의미 : USART_TDR이 empty 이므로 데이터를 USART_TDR 에 기록가능 상태. 

TC bit.
1. 프레임 송신 완료되고, TXE bit 가 1되면 TC bit 1된다. 
2. TCIE bit (register USART_CR1) 가 1이면 TC 인터럽트 발생.
3. TC bit 은 software clear 처리한다. TCCF bit (register USART_ICR) 에 1을 기록하든지 혹은 USART_TDR 에 데이터 기록하면 TC bit clear 됨. 


 


 

 

USART Receiver

 

수신 절차.
1. RE bit (USART_CR1 register) set 하면 receiver는 start bit searching enable 된다.
2. shift register의 데이터가 USART_RDR 로 이전되었을때 RXNE bit set 된다. 즉, 데이터 수신했고 읽을 수 있다는 의미.
3. multibuffer 모드인 경우, USART_RDR 을 DMA read 하면 RXNE는 clear 된다.
4. single buffer 모드인 경우, RNXE clear 는 소프트웨어적으로 이뤄져야한다.

 


 

 

Hardware Flow Control

 
 
RTS flow control : register USART_CR3 의 RTSE bit set 하면 enable.
CTS flow control : register USART_CR3 의 CTSE bit set 하면 enable.


RTS flow control

USART receiver 가 신규데이터 수신가능한 동안 RTS 핀으로 Low 출력. receive register 가 full 인 경우 High 출력.


CTS flow control


next frame 전송시 CTS 값이 Low 이면 출력하고, CTS 값이 High 이면 출력하지 않음. 전송중 CTS가 High 가 된 경우엔 현재 송신 중데이터 전송은 완료하고 중지함.


 


 

 

USART DMA

 


Tx using DMA

- 연속 프레임 송신 위하여, TXE bit (USART_ISR register) 를 software clear 해야한다.

- 송신완료 모니터링 수단으로  TC 활용가능하다. TC 는 마지막프레임의 최종 송신완료되면 hardware set 된다.


Rx using DMA

- 연속 프레임 수신 위하여,  RXNE bit (USART_ISR register) 를 software clear 해야한다.

 


 





 

 본 글이 포함된 상위 정리장소 : http://igotit.tistory.com/244

 

 


///본글 단축주소 : https://igotit.tistory.com/787




첫글등록 : 2016년 7월3일.

최종수정 : 2018년 12월10일.


댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5