Minds gone blank - location for USART initialisation

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi it's Saturday and not had enough beer LOL

 

 

I'm going to need to change Baud rate often on across different USARTs  of a 2560.

 

1) Do I stick initialisation the normal routines (enable, start/stop, Parity, Baud) above or below int main() - (its above isn't it?)

2) Then, can I just change UBRR within the functions as needed - that's a yes right?

 

Whoever would have thought senility started at 50 aarrgghh

 

thanks

Chaps and Chapesses

 

This topic has a solution.
Last Edited: Sat. Nov 14, 2020 - 05:38 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Put everything to do with UART in uart.c and uart.h files - it's called "modularisation"

 

But if it is all going in the same file as main() it doesn't really matter if you put the UART  functions above or below main() but if they go below you will need DECLARATIONS above (with DEFINITIONS below).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for the confirmation

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not about being "above or below main()"

 

The 'C' programming language requires that things must be declared (or defined) before they are used - that's the criterion you need to meet.

 

This is standard 'C' stuff - not specific to AVR or microcontrollers; and nothing to do with the UART.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...