hexagon5un / AVR-Programming

Code examples for the book "Make: AVR Programming"
http://littlehacks.org/AVR-Programming
MIT License
725 stars 340 forks source link

Update USART.c #17

Closed pilinux closed 8 years ago

pilinux commented 8 years ago

I have atmega8 and for that uC, when I tried to compile I got error: UCSRA0A undeclared (first use in this function) and same error messages for UBRR0H, UBRR0L, U2X0, UCSR0B, TXEN0, RXEN0, UCSZ01, UCSZ00, UDRE0, RXC0 & for UDR0. So I updated the file by dropping all 0s. Now it works perfectly for atmega8. I also have tested the modified code for atmega168p (which you have used in your Makefile) and it worked without any error. I think you should add this updated file to your project :) Thank you!

hexagon5un commented 8 years ago

Heya!

Sorry I took so long in responding to this one. The Mega8-style macros are old and deprecated. They supported them in (some? all?) of the other chips where they could, but you should not get used to thinking of them as interchangeable.

On the chips with more than one USART, for instance, they're USART0 and USART1 and etc. For all of the new parts, Atmel has moved toward the consistent naming system with a 0 even when there's only one USART.

The standard way of dealing with this is to wrap the Mega8 code in #ifdef brackets, but I find that makes things a lot less readable, so I'm averse to doing that with the code in the book.

All of this is my long-winded way of saying, "yeah, that's the old style, and I don't think we should go back to it".