Compared to the u2
, the u4
has:
- More RAM (2.5k vs. 1k)
- More pins (48 vs. 32)
- Analog-to-digital converters instead of just analog comparators
- Low frequency crystal option instead of full swing crystal option
- An I2C interface.
To answer this, I did a DigiKey search for each part number and compared the result tables. This is easier than comparing the datasheets, although datasheets are the most accurate place to find information. For example, the oscillator information in Digikey suggests that the u4
requires an external oscillator, while the u2
requires an internal oscillator. This is not the case; the u4
ships with the external oscillator as the default and the u2
ships with the internal oscillator as a default, but both can use internal and external clock sources.
To understand all of this stuff, take a look at "Table 18-1. Equations for Calculating Baud Rate Register Setting" from the datasheet on page 189. The equation you suggested you found in some example code
UBRR1 = (F_CPU / 4 / baud - 1) / 2;
... is kind of close to the equation for Asynchronous Double Speed mode (U2Xn = 1)... but not exactly.
If you know the baud rate and crystal speed you intend to operate at, I would just pull the register settings out of "Table 18-9. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies" on datasheet page 210 and call it a day. The only reason to use any of those equations is if you want to be able to change the settings dynamically at run-time for some reason (or if you want to do thins "elegantly" in software, I prefer compile time certainty for something like this to remove doubt).
For the settings you outlined in your question, that would be:
UCSR1A = 0; // importantly U2X1 = 0
UCSR1B = 0; // interrupts enabled in here if you like
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); // no parity, 8 data bits, 1 stop bit
UCSR1D = 0; // no cts, no rts
UBRR1 = 103; // 9600 baud @ 16MHz XTAL with U2X1 = 0
As a side note, while the hardware does store the baud rate register (UBBRn) as two 8-bit registers, in software there is no need to treat it as such. You can access the High and Low registers (e.g. UBRR1H and UBRR1L respectively) but you can also just
assign to (or read from) the named "combined" register as though it was a 16-bit register.
UBRR1 = 0x0343;
is functionally equivalent to UBRR1H = 0x03; UBRR1L = 0x43;
Best Answer
I am not sure where you have got the part numbers that are in your question title, but it looks like for a ATmega32U4 you have only four options (see page 422): two package and two oscillators.
The -AU/-MU select the 44ML/44PW package respectively, whereas the 32U4/32U4RC select the oscillator option. They both should be the same internally except the default oscillator. They both need an external oscillator if you want to run them at > 8MHz. See page 29 section 6.2.1 and 6.2.2 - the difference is how the fuses are programmed when shipped. So, the 32U4-AU is set by default to work with the external oscillator, whereas the 32U4RC-AU is set to work with the internal oscillator and both are 44ML TFQP package. So, if you get the 32U4-AU, you will need to connect it to an oscillator to be able to reprogram it.
As for the additional -R letter I would guess that it signifies that the parts are packaged and shipped in a reel.