Docsity

UART and USART table, Cheat Sheet of Microprocessors

Partial preview of the text

Download UART and USART table and more Cheat Sheet Microprocessors in PDF only on Docsity!

USART and UART Needs Requires clock and data signals Requires only data signals Mode Half-duplex mode Full-duplex mode Speed Higher Lower Data Transmits data in the form of data Transmits data in the form of data bytes transmission blocks Data Fixed rate Different speeds transmission rate Transfer Higher data rate Range between 4800, 9600, and 38400 speed bps Baud-rate The receiver doesn't need toThe recipient must know the know the baud rate of the sender transmitter's baud rate before gathering as it is determined by the data line offered by the clock signal. Nguyén Trung Higu USART Pin [PaMERCRIT PSO ET] a [at Paovanciensty (PCINT9/CLKO/T1) PBI 2 39 Jj Pat (ADCL/PCINT)) (PCINTIO/AINT2/AIND) PB2 FR] 3 36 [} Pa2(ape2rcint2) (PCINT1I/OCOA/AIN1) PB3 J] 4 37 [J PAS(ADCYVPCINTS) (PCINTI2/0CUB/ 55} PB4 5 36 [ij PA4(ADC4/PCINT4) (PCINTI3/MOS}) PBS 6 36 [3 PAS(ADCS/PCINTS) (PCINT14/MISO) PB6 7 34 [J PAB(ADCO/PCINTS) 8 j (PCINT! 5//SCK) PB7 33 [Jj PAT(ADC7/PCINT7) RESET 32 [J] AREF vec GND GND [J avec XTAL2 PC7 (TOSC2/PCINT23) XTALY PC6 (TOSC1/PCINT22) (PCINT24/RXD0) PDO PCS (TDUPCINT21) (PCINT25/TXDV) POI PCA (TDO/PCINT20) (PCINT2@/RXDIANTO) PD2 PC3 (TMS/PCINT!9) (PCINT27/TXDI/INT 1) PDS: PC2 (TCK/PCINTI8) (PCINT28/XCK1/OCIB) PD4 PC1 (SDA/PCINTI7) (PCINT29/OC1A) PDS: PCO (SCL/PCINTI6) USART1 (PCINTIVOCABICPL) PDE PD? (OC2/PCINT31) USARTO USART * Two USART instances: * USARTO: RxDO (PDO), TxDO (PD1), XCKO (PBO) * USART1: RxD1 (PD2), TxD1 (PD3), XCK1 (PD4) Full Duplex (if UART) and Half Duplex (if USART) * 3 special function registers: UCSRxA, UCSRxB, UCSRxC UDRx (x=0,1): same address but 2 buffers; 1 buffer for transmission and 1 buffer for reception ¢ Baud rate (serial port frequency of operation): configure by UBRRxL:UBRRxH (x=0,1) Nguyén Trung Hig 2 USART Clock Generator Down-Counter | °|_ To Transmitter Use in mode “| y synchronous ae Tego sex [7 L_ Br Detector UART 7; To Receiver =0: = ose __ U2Xn =0: faut 8(UBRRn +1) USART _ Sose _ osc U2Xn = 4: Sau 16(UBRRn +1) Sout = 2(UBRRn +1) USART Baud Rate Register Example Calculate Baudrate SRAM address: UART UBRROL (0xC4) and UBRROH (0xC5) Tose UBRR1L (0xCC) and UBRR1H (0xCD) U2Xn = 0: Soaud = T6(UBRRn +1) 6(UBRRn +1) ats 14 8 2 1" 10 9 8 _ ose econ ; a a = Uaxn = 1: San = 8(UBRRn +1) Reset 0 0 0 0 an 7 6 5 4 3 2 1 0 Example: Calculate UBRRO value to provide 4800 baud for a — — a ay a ax _USARTO operating in mode UART. Given fosc = 8MHz. Reset 0 0 0 0 0 0 ° 0 ¢ If U2X0 = 1: i ° Sosc___, 4gqg = 8.10" — UBRRO = 207 Example: Baud“ 8(UBRRO +1) 8(UBRRO +1) LDI —R16,HIGH(21) a. STS _UBRROH,R16 * If U2X0 = 0: ; LDI — R16,LOW(21) fose 8.10 = — 4800 = — UBRRO ~103 STS — UBRROL,R16 , Saat = TECOBRRO+D) 16(UBRRO +1) om Error in Baudrate UBRRx Settings fose = 8.0000MHz a .0592MHz * Due to rounding, there is a slight error. U2x=0 u2x=4 u u2x=4 |uz UBRRn Error UBRRn Error UBRRn Error | UBRRn Error UBRRn | Error 2400 207 02% 416 0.1% 287 0.0% 575 0.0% 383 0.0% 767 0.0% Example: Calculate the error in the previous example 4800 103 0.2% 207 0.2% 143 0.0% 287 0.0% 191 0.0% 383 0.0% 9600 51 0.2% 103 0.2% 71 0.0% 143 0.0% 95 0.0% 191 0.0% * If U2X0 =1: UBRRO=207 14.4k 34-08% 6B 0.6% 47 0.0% 95 0.0% 63 0.0% 127 0.0% ti 8.10° 19.2k 25 (0.2% 51 0.2% 35 0.0% 71 0.0% 47 0.0% 95 0.0% = Osc = x Soaua = 8(UBRRO +1) > Seawa = (207 +1) ~ 4807.7(baud) 28.8k 16 2.1% 34 —--0.8% 23 0.0% 47 0.0% 31 0.0% 63 0.0% 4807. 7 38.4k 12 0.2% 25 0.2% 17 0.0% 35 0.0% 23 0.0% 47 0.0% Bron) =( 2300 -1} 100% = 0.16% 57.8k 8 35% 16 21% 11 0.0% 23 0.0% 15 0.0% (31 0.0% 76.8k 6 -7.0% 12 0.2% 8 0.0% 17 0.0% 11 0.0% 23 0.0% ¢ If U2X0=0: UBRRO =103 116.2k 3 85% 8 3.5% 5 0.0% 11 0.0% 7 0.0% 15 0.0% ti 8.10% 230.4k 1 85% 3 8.5% 2 0.0% (5 0.0% 3 0.0% 7 0.0% = OSC. = ~~ Soaua = 16(UBRRO +1) > Saud = 16(103 +1) = 4807.7(baud) 250k 1 0.0% 3 0.0% 2 -7.8% 5 78% 3 78% 6 5.3% 0.5M 0 0.0% 1 0.0% - - [2 -7.8% 1 7.8% 3 7.8% 4807.7 - - = > - 78% 78% Error(%) = -1).100% = 0.16% , 1M 0 0.0% 0 7.8% 1 7.8% 4800 ~ Max.(“) 0.5Mbps Mbps 691.2kbps 1.3824Mbps — 921.6kbps 1.8432Mbps UCRSC Example: Initialize the UART Bit 7 é 5 4 3 z 7 ° USART_INIT: we oe ves Ce | See) LDI.—_—aR146,(1<