OSU ECE 473 - AVR306: Using the AVR® UART in C

Unformatted text preview:

FeaturesDescriptionPolled UARTInterrupt Controlled UARTUsagevoid InitUART ( unsigned char baudrate );unsigned char ReceiveByte ( void );void TransmitByte ( unsigned char data );unsigned char DataInReceiveBuffer ( void );1AVR306: Using the AVR®UART in CFeatures• Setup and Use of the AVR UART• Code Examples for Polled and Interrupt Controlled UART• Compact Code• C Code Included for AT90S8515DescriptionThis application note describes how to set up and use the UART present in most AVRdevices. C code examples are available for polled and interrupt controlled UARTapplications.Polled UARTThe application is continously checking the UDRE bit in the UART Status Register tocontrol when the UART has finished sending a byte. When receiving data, the applica-tion is continously checking the RXC bit in the UART Status Register to control whentheUARThascompletedreceivingabyte.Interrupt Controlled UARTThe UART generates an interrupt when the UART has finished transmitting or receiv-ing a byte. The interrupt handling routines uses modulo 2n addressing of circularbuffers for buffering incoming and outgoing data. The buffer sizes must be definedbefore using the routines. Set the UART_RX_BUFFER_SIZE andUART_TX_BUFFER_SIZE variables to the buffer size in bytes. Note that these vari-ables must be a power of 2. If not, a compiler error message will be flagged.An extra function is addedta to the UART2 example code. The DataInReceiveBufferreturns zero if the receive buffer does not contain any data. This function does, in con-trast to the ReceiveByte function, not wait for incoming data, but returns immediatelythe status of the buffer. Note: this routine does not return the number of bytes in thebuffer.Table 1 . Properties of Polled/Interrupt Controlled UART RoutinesPolled UART Interrupt controlled UARTCompact code Reasonable code sizeApplication busy while communicating Application free while communicating8-bitMicrocontrollerApplicationNoteRev. 1451B–AVR–07/022AVR3061451B–AVR–07/02Usage Both examples use the same set of routines. If other devices than AT90S8515 is used,the include file in the code must be changed accordingly.void InitUART( unsigned char baudrate );Enables the UART and sets the baud rate. Using baud rates that differs more than±0.5% is not recommended. Please refer to the UART section in the data sheet forselectingthebaudrate.ThevaluepassedtothisfunctionwillbewrittentotheUARTBaud Rate Register.unsigned char ReceiveByte(void);Waits for one byte to be received and returns it's value.void TransmitByte( unsigned char data );Waits for transmission to be allowed, sends byte given as parameter to the UART trans-mitter and returns.unsigned charDataInReceiveBuffer(void);Returns zero (0) if the receive buffer is empty.Printed on recycled paper.© Atmel Corporation 2002.Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company’s standard warrantywhich is detailed in Atmel’s Terms and Conditions located on the Company’s web site. The Company assumes no responsibility for any errorswhich may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and doesnot make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are grantedby the Company in connection with the sale of Atmel products, expressly or by implication. Atmel’s products are not authorized for use as criticalcomponents in life support devices or systems.Atmel Headquarters Atmel OperationsCorporate Headquarters2325 Orchard ParkwaySan Jose, CA 95131TEL 1(408) 441-0311FAX 1(408) 487-2600EuropeAtmel SarlRoute des Arsenaux 41Case Postale 80CH-1705 FribourgSwitzerlandTEL (41) 26-426-5555FAX (41) 26-426-5500AsiaRoom 1219Chinachem Golden Plaza77 Mody Road TsimhatsuiEast KowloonHong KongTEL (852) 2721-9778FAX (852) 2722-1369Japan9F, Tonetsu Shinkawa Bldg.1-24-8 ShinkawaChuo-ku, Tokyo 104-0033JapanTEL (81) 3-3523-3551FAX (81) 3-3523-7581Memory2325 Orchard ParkwaySan Jose, CA 95131TEL 1(408) 441-0311FAX 1(408) 436-4314Microcontrollers2325 Orchard ParkwaySan Jose, CA 95131TEL 1(408) 441-0311FAX 1(408) 436-4314La ChantrerieBP 7060244306 Nantes Cedex 3, FranceTEL (33) 2-40-18-18-18FAX (33) 2-40-18-19-60ASIC/ASSP/Smart CardsZone Industrielle13106 Rousset Cedex, FranceTEL (33) 4-42-53-60-00FAX (33) 4-42-53-60-011150 East Cheyenne Mtn. Blvd.Colorado Springs, CO 80906TEL 1(719) 576-3300FAX 1(719) 540-1759Scottish Enterprise Technology ParkMaxwell BuildingEast Kilbride G75 0QR, ScotlandTEL (44) 1355-803-000FAX (44) 1355-242-743RF/AutomotiveTheresienstrasse 2Postfach 353574025 Heilbronn, GermanyTEL (49) 71-31-67-0FAX (49) 71-31-67-23401150 East Cheyenne Mtn. Blvd.Colorado Springs, CO 80906TEL 1(719) 576-3300FAX 1(719) 540-1759Biometrics/Imaging/Hi-Rel MPU/High Speed Converters/RF DatacomAvenue de RochepleineBP 12338521 Saint-Egreve Cedex, FranceTEL (33) 4-76-58-30-00FAX (33) [email protected] Sitehttp://www.atmel.com1451B–AVR–07/02 0MATM E L®and AVR®are the registered trademarks of Atmel.Other terms and product names may be the trademarks of


View Full Document

OSU ECE 473 - AVR306: Using the AVR® UART in C

Download AVR306: Using the AVR® UART in C
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view AVR306: Using the AVR® UART in C and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view AVR306: Using the AVR® UART in C 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?