220 likes | 523 Views
Programming Microcontroller USART Universal Synchronous/Asynchronous Receiver Transmitter Autumn 2012. Typical serial communication (low level). Full-duplex interface. Receive. Transmit. Device 1 (Data Set). Device 2 (Data Terminal). Transmit. Receive. -PC -embedded system - modem
E N D
Programming Microcontroller USART Universal Synchronous/Asynchronous Receiver Transmitter Autumn 2012 UART - Serial communic.
Typical serial communication(low level) UART - Serial communic. Full-duplex interface Receive Transmit Device 1 (Data Set) Device 2 (Data Terminal) Transmit Receive -PC -embedded system -modem -barcode reader -printer -display (with terminal emulation software) -data logger -sensor (simple or complex) -dongle (security element) -I/O module (digital, analog, encoder, PT100) -wireless interface • PC • Embedded system
RS-232-C pin assignmentsD-Sub male on PC UART - Serial communic. Male -> Stecker Female -> Buchse RS-232-C: Radio Sector, American Standard since 1969s EIA: Electronic Industry Alliance
Serial data format(logical representation) UART - Serial communic. 1-2 stop bits msb lsb 1 5-8 data bits 0 n Parity bit if enabled start time lsb: least significant bit (20) msb: most significant bit (2 db-1) Normally one Byte is sent as 8 data bits Or: One Byte is sent as 7 data bits + parity 1 bit time = 1 / baud rate Example: parity enabled, 2 stop bits
Hyperterminal usage UART - Serial communic. Start -> Zubehör -> Kommunikation -> Hyperterminal Go offline Configure COM-Port: File->Properties Xon/Xoff: Software handshake (Exchange on..) <ctrl-q>/<ctrl-s> both sides must implement this software handshake. The sender has to stop almost immediately upon reception of Xoff character Binary data transmission is not possible. Hardware: RTS/CTS hardware handshake guarantees loss-free transmission on a byte level and allows binary data transmission
Simple serial communication (3-wire) Multiple physical interfaces: EIA-232 Peer-to-peer (former RS-232-C 1969). Gnd based (-15..-3,3..15 V) EIA-485 Party Line, multi-point link (SCSI, ISDN, ... EIA-422 : Balanced lines, no ground link (D+/D-) on drivers up to 1'000m @ 100 kbps. Point-to-point or multi-drop. 0-5 V. Twisted-pair cable Easy setup Direct programming Byte level only USB will not replace cheap and simple communications UART – What is it good for? UART - Serial communic. EIA: Electronic Industry Alliance
EIA-485 Party Line, multi-point link UART - Serial communic.
Hardware flow control UART - Serial communic. nRTS will be switched on and off by programmable receiver DMA watermarks
Full duplex, asynchronous communications NRZ standard format (Mark/Space) Fractional baud rate generator systems A common programmable transmit and receive baud rates up to 4.5 MBits/s Programmable data word length (8 or 9 bits) Configurable stop bits - support for 1 or 2 stop bits LIN (Local Interconnection Network) 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 Transmitter clock output for synchronous transmission IrDA SIR Encoder Decoder Support for 3/16 bit duration for normal mode Smartcard Emulation Capability The Smartcard interface supports the asynchronous protocol Smartcards as defined in ISO 7816-3 standards 0.5, 1.5 Stop Bits for Smartcard operation UART features (1/3) UART - Serial communic.
Single wire half duplex communication Configurable multi buffer communication using DMA (direct memory access) Buffering of received/transmitted bytes in reserved SRAM using centralized DMA Separate enable bits for 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 UART features (2/3) UART - Serial communic.
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 - enter into mute mode if address match does not occur Wake up from mute mode (by idle line detection or address mark detection) Two receiver wakeup modes: Address bit (MSB, 9th bit), Idle line UART features (3/3) UART - Serial communic.
UART Block diagram UART - Serial communic. Ref. RM0008 Reference manual, figure 277
UART register boundary addresses UART - Serial communic. Ref. RM0008 Reference Manual, table 3
UART register offset addresses UART - Serial communic. Ref. RM0008 Reference Manual, table 198
Status register (USART_SR) CTS: Clear to send TXE: Transmit data register empty TC: Transmission complete RXNE: Read data register not empty NE: Noise error FE: Frame error PE: Parity error Data register (USART_DR) Contains the received or transmitted data character, depending it is read from or written to UART register description (1/4) UART - Serial communic. Ref. RM0008 Reference Manual, chapter 27.6
UART register description (2/4) UART - Serial communic. • Control register 1 (USART_CR1) • UE: USART enable • M: Word length • PCE: Parity control enable • PS: Parity selection • PEIE: Parity interrupt enable • TXEIE: TXE interrupt enable • TCIE: Transmission complete interrupt enable • RXNEIE: RXNE interrupt enable • TE: Transmitter enable • RE: Receiver enable
UART register description (3/4) UART - Serial communic. • Control register 2 (USART_CR2) • STOP: Stop bits • CLKEN: Clock enable • CPOL: Clock polarity • CPHA: Clock phase
UART register description (4/4) UART - Serial communic. • Control register 3 (USART_CR3) • CTSIE: CTS interrupt enable • CTSE: CTS enable • RTSE: RTS enable • DMAT: DMA enable transmitter • DMAR: DMA enable receiver • HDSEL: Half-duplex selection • EIE: Error interrupt enable
The Baud rate for the receiver and transmitter (Rx & Tx) are both set to the same value USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register Fractional Baud Rate generator UART - Serial communic.
Error calculation for programmed baud rates UART - Serial communic. Ref. RM0008 Reference Manual, table 192
USART2 port functional description PD5: Alternate push-pull PD6: Input floating USART2 port remap PD5 USART_TX PD6 USART_RX Pin connections of USART2 UART - Serial communic. RM0008 Reference manual, Table 53