programming microcontroller usart universal synchronous/asynchronous receiver transmitter
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
MS_uC / fue1 / V01 4- 1
UART - Serial communic.
Programming MicrocontrollerUSART
Universal Synchronous/Asynchronous Receiver Transmitter
Autumn 2012
MS_uC / fue1 / V01 4- 2
UART - Serial communic. Typical serial communication(low level)
Full-duplex interface
Device 1(Data Set)
Device 2(Data Terminal)
-PC-Embedded system
-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
Transmit
ReceiveTransmit
Receive
MS_uC / fue1 / V01 4- 3
UART - Serial communic. RS-232-C pin assignmentsD-Sub male on PC
PinDB9
PinDB25
Symbol Direction
Text
Out
In
1 8 DCD Data Carrier Detect
2 3 Rx Receive Data
3 2 Tx Transmit Data
4 20 DTR Data Terminal Ready
5 7 Gnd Signal Ground
6 6 DSR Data Set Ready
7 4 RTS Request to Send
8 5 CTS Clear to Send
9 22 RI Ring IndicatorRS-232-C: Radio Sector, American Standard since 1969sEIA: Electronic Industry Alliance
Male -> SteckerFemale -> Buchse
MS_uC / fue1 / V01 4- 4
UART - Serial communic. Serial data format(logical representation)
5-8 data bits
Parity bit if enabled
1-2 stop bitsmsblsb
start
1
n0
time
lsb: least significant bit (20)msb: most significant bit (2 db-1)
1 bit time = 1 / baud rate
Example: parity enabled, 2 stop bits
Normally one Byte is sent as 8 data bitsOr: One Byte is sent as 7 data bits + parity
MS_uC / fue1 / V01 4- 5
UART - Serial communic. Hyperterminal usage
Start -> Zubehör -> Kommunikation -> HyperterminalGo offlineConfigure COM-Port: File->Properties
Xon/Xoff: Software handshake (Exchange on..)<ctrl-q>/<ctrl-s>
both sides must implement thissoftware handshake. The senderhas to stop almost immediatelyupon reception of Xoff characterBinary data transmission is notpossible.
Hardware: RTS/CTS hardware handshakeguarantees loss-free transmissionon a byte level and allows binary data transmission
MS_uC / fue1 / V01 4- 6
UART - Serial communic. UART – What is it good for?
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
EIA: Electronic Industry Alliance
MS_uC / fue1 / V01 4- 7
UART - Serial communic. EIA-485 Party Line, multi-point link
MS_uC / fue1 / V01 4- 8
UART - Serial communic. Hardware flow control
nRTS will be switched on and off by programmable receiver DMA watermarks
MS_uC / fue1 / V01 4- 9
UART - Serial communic. UART features (1/3)
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
MS_uC / fue1 / V01 4- 10
UART - Serial communic. UART features (2/3)
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
MS_uC / fue1 / V01 4- 11
UART - Serial communic. UART features (3/3)
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
MS_uC / fue1 / V01 4- 12
UART - Serial communic.
UA
RT B
lock
d
iag
ram
Ref. RM0008 Reference manual, figure 277
MS_uC / fue1 / V01
UART register boundary addresses4- 13
UART - Serial communic.
Ref. RM0008 Reference Manual, table 3
Boundary address Peripheral Bus
0x4000_4400 – 0x4000_47FF USART2 APB1
0x4000_4800 – 0x4000_4BFF USART3 APB1
0x4000_4C00 – 0x4000_4FFF USART4 APB1
0x4000_5000 – 0x4000_53FF USART5 APB1
0x4001_3800 – 0x4001_3BFF USART1 APB2
MS_uC / fue1 / V01 4- 14
UART - Serial communic. UART register offset addresses
Ref. RM0008 Reference Manual, table 198
MS_uC / fue1 / V01 4- 15
UART - Serial communic. UART register description (1/4)
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
Ref. RM0008 Reference Manual, chapter 27.6
MS_uC / fue1 / V01UART register description (2/4)
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
4- 16
UART - Serial communic.
MS_uC / fue1 / V01 UART register description (3/4)
Control register 2 (USART_CR2)
STOP: Stop bits CLKEN: Clock enable CPOL: Clock polarity CPHA: Clock phase
4- 17
UART - Serial communic.
MS_uC / fue1 / V01UART register description (4/4)
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
4- 18
UART - Serial communic.
MS_uC / fue1 / V01 4- 19
UART - Serial communic. Fractional Baud Rate generator
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
MS_uC / fue1 / V01
Error calculation for programmed baud rates4- 20
UART - Serial communic.
Ref. RM0008 Reference Manual, table 192
MS_uC / fue1 / V01 4- 21
UART - Serial communic. Pin connections of USART2RM0008 Reference manual, Table 53
USART2 port functional description PD5: Alternate push-pull PD6: Input floating
USART2 port remap PD5 USART_TX PD6 USART_RX