Maker Pro
Maker Pro

ATMEGA2560//Atmel Doccumentation Error?

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
In the Data Sheet for the ATMEGA2560 the following code example is given to initialize a UART:

Code:
Assembly Code Example(1)
USART_Init:
; Set baud rate
sts UBRRnH, r17
sts UBRRnL, r16
ldi r16, (1<<U2Xn)
sts UCRnA, r16
; Enable receiver and transmitter
ldi r16, (1<<RXENn)|(1<<TXENn)
sts UCSRnB,r16
; Set frame format: 8data, 1stop bit
ldi r16, (2<<UMSELn)|(3<<UCSZn0)
sts UCSRnC,r16
ret
(Taken from Page 211, 2549P–AVR–10/2012)

Great News....It works! However, later on in the documentation.....

The UMSELn Table Breakdown of the UCSRnC Registers shows:

Code:
Table 22-4. UMSELn Bits Settings
UMSELn1 UMSELn0 Mode
0 0 Asynchronous USART
0 1 Synchronous USART
1 0 (Reserved)
1 1 Master SPI (MSPIM)
(Taken from Page 225, 2549P–AVR–10/2012)

When it is all said and done, $86 is the most commonly used setting for RS232-TTL type comm, which obviously shows UCSRnC.7 as being Set and USCRnC.6 as being cleared....But the results of the "example code" work perfectly, LoL! Not a huge deal until you run into a comm port that isn't responding correctly and you are pulling your hair out attempting to get it to work.....

For giggles i will point out that the ACTUAL PROBLEM I was having had nothing to do with my code or the UART settings.....Turns out the last batch of ARDUINO 2560 Clones I received have a silkscreen error! LoL, the Rx and Tx pins are mislabeled on UART1 (simply reversed).....It turns out that there isn't a register setting to make the Rx line transmit!

I caught the apparent Atmel Documentation Error while attempting to figure out why I couldn't Tx to a slave device.....Likely the documentation has been updated, or there has been a "Notice" of some sort about the apparent error, but I found the Actual Problem before I found any reference to the contradiction.....

Six hours of my life wasted....but other than that no real harm or foul.

Cheers!

Fish
 
Top