120 likes | 278 Views
Using the AVR UART. Overview. How do I know what to do? What do I do? Setup the Wunderboard Setup the Host computer Setup the #define statements. How do I know what to do?. The first step is to read even if it does not make sense the first time Second is to ask
E N D
Overview • How do I know what to do? • What do I do? • Setup the Wunderboard • Setup the Host computer • Setup the #define statements
How do I know what to do? • The first step is to read even if it does not make sense the first time • Second is to ask • Third is to hope and pray ;)
What do I do? • When working with lots of 'unknowns' limit yourself to one unknown at a time. • Don't try new software on a PC and a microcontroller while also using new hardware. • Limit your uncertainty
Setup the Wunderboard • The Wunderboard code needs three functions • unsigned char InitializeUART () • unsigned char SendByteUART () • unsigned char SendStringUART()
unsigned char InitializeUART () • This function setup the Wunderboard to transmit serial data • You need to set the values of the UBRRn, UCSRnA, UCSRnB, and UCSRnC registers • Make sure you read the datasheet, section 18.10 thoroughly
unsigned char SendByteUART () • This function should check if the UART is ready to send a new byte. • If it is, it should send other wise it should exit immediately • Don't forget your return value!
unsigned char SendStringUART() • This function should try to send a string of characters by repeatedly calling the SendByteUART() function • If the first character it tries to send fails, the function should exit immediately • Otherwise the function blocks until the entire string is sent.
Setup the Host computer • To see the serial data being sent from the Wunderboard, you need to setup a 'terminal' program • Make sure you use the same settings as your Wunderboard
Setup the #define statements • Finally once you know your code works, encase the UART material in #ifdef preprocessor statements • This lets you enable and disable the UART with a single line.
Prelab Walk-Through • Lets go through the prelab together
Parting Thoughts • Look at return values and write functions that use them • Read everything • Ask for help