The Math Behind the AVR Assembly UART Functions Found in ATMEL AppNote AVR305

Bit length converted to clock cycles,

Bit Length

An example using an 8MHz clock and 19,200 baud rate:

Bit Length Example

The transmit and receive functions use 9 cycles and rcall/ret are 7 cycles (note: the delay subroutine is called twice),

dContinuing our example:

d Example

With the following delay routine, total execution time is 3*b cycles plus 7 cycles for the rcall/ret:

              rcall UART_delay
UART_delay:   ldi  temp, b
UART_delay1:  dec  temp
              brne UART_delay1

Continuing our example,
c Example
The actual delay generated, calling delay twice is,
Continuing our example:
delay Example
Resulting baud rate error,
Continuing our example:
error Example
Here are the transmit, receive and delay functions.


About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s