I have a Nano Every and I am using Serial1.begin(baud) to initialize the HW Serial Port RX/TX.
If baud is set to 500k or 1M, I can see using oscilloscope on TX pin that the bit rate is indeed 500kbps of 1Mbps.
But if I set it to anything higher than 1M (eg. 2M), the bit rate seems to max out to only 1Mbps.
I have tried similar experiment with a Mega board on Serial1 and on Mega I can get 2Mbps. But not on Nano Every.
Does anybody have any idea what is going on and how to overcome this issue? Thank you.
Hi @ghariman
The message on the link looks as a closest copy of yours. Are you and @codercat1 a brothers or the same person?
Hi @b707,
No. I am not the same person nor related to that other guy. His problem seems to be on his Mega he cannot get 1Mbps. On my Mega I can get higher than 1Mbps (like 2Mbps). My problem is on my Nano Every board. I can get up to 1Mbps but higher than that, then I can only see max 1Mbps.
I hope somebody has experienced these troubles before and knows a fix for it especially for the Nano Every.
Just in sake of curiosity - why do you need such high baudrate?
Because I am communicating UART with a chip (from a company I work for) that is set to receive UART at 2Mbps. I can use the Mega board I have. But I want to use the Nano Every as it is smaller.
I can't recommend Every to use. The AVR core for Every a quite raw and contains a few very weird things... for example? on the Every the LOW and HIGH are not the 0 and 1.
I think a RP2040 board will be a better solution to use as UART bridge.
Apples and oranges I'm afraid. The 4809 is a very different processor than the 328P or 2560. Just because something works on one doesn't mean it will work on the other.
In the case of the 4809, the minimum value allowed in the BAUD register is 0x40 (see the 4809 datasheet, section 10.3.4.1.1 in my copy). Specifying 1000000 for the baud rate results in
(((8 * F_CPU) / baud) + 1) / 2
(in boards.txt, the F_CPU for the Every is specified as 16000000) so
(((8 * 16000000 ) / 1000000 + 1) / 2
((128000000 / 1000000 + 1) / 2
(128 + 1) / 2
129 / 2
64.5
truncated to 64
which is 0x40
So 1000000 is the highest baud rate the Nano Every's UART can run at.
Interestingly, but totally irrelevant in this case, you can bump the Every's clock speed from 16MHz to 20MHz simply by changing the f_cpu and OSCCFG values in boards.txt, which would allow a maximum baud rate of 1250000. I can verify that this indeeds works. Not that it helps the OP get to 2000000 baud though!
Hi @van_der_decken, Thank you for the detailed information. So I am in a pickle. I need an Arduino with the form factor of Nano that has dedicated HW Serial (like Every) but that can do 2Mbps. Do you have any idea which of the other Nano families meet this criteria?
Nano R4 will do 2Mbps based on very preliminary investigation (i.e. I ran a sketch that set Serial1 to 2000000, output the U character - hex 55, binary 01010101 - over and over again and looked at the waveform to see that a bit width was indeed 500ns). Now, whether it works is an entirely different question. The core for the R4 is nowhere near being a mature product and is still very much bleeding edge. If you got that route, don't be surprised if you run into other major hassles.
There may be others but that's the only other type I have and could check.
I always recommend MegaCoreX for the NanoEvery. Indeed, it contains a file called common.h with these #defines
#define LOW 0
#define HIGH 1
I'm not sure why you say the LOW and HIGH definitions do not exist in the Arduino megaavr core. In that core, there is a file called Arduino.h which contains this
#include "api/ArduinoAPI.h"
You can see that file here
[GitHub - arduino/ArduinoCore-API: Hardware independent layer of the Arduino cores defining the official API]
(GitHub - arduino/ArduinoCore-API: Hardware independent layer of the Arduino cores defining the official API)
and in it's common.h file you find this enum
typedef enum {
LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;
and digitalRead() returns the PinStatus
PinStatus digitalRead(pin_size_t pinNumber);
Why do you say
on the Every the
LOWandHIGHare not the 0 and 1.
I have done many project with the Nano Every, and using MegaCoreX I find it to be an excellent platform for 5v projects.
I looked at the RA4M1 user manual. Below is an excerpt from the SCI section:
It says that 6666666 bps is possible with the maximum PCLKA value of 40 MHz, but I think it's right what @van_der_decken stated.
You can consider an Arduino Micro, SparkFun Pro Micro or Pololu A-Star 328PB Micro.
Just use HIGH and LOW and don’t worry about the underlying representation…
Doing anything else is actually working against the spec and poor coding based on bad habits in my opinion.
PS: Note that your statement is not entirely true as they are coded as 0 for LOW and 1 for HIGH, see
What’s different is the type of HIGH and LOW is not int but there are implicit promotion rules that will get you 0 and 1. It’s the other direction that is more tricky if you don’t use the right type (like there is no implicit promotion from bool to PinStatus type for example )
The older AVR Arduinos used a double-speed mode for the UART clock, because it achieves better accuracy for 115200bps (or something.)
The ATmega4809 has a "fractional BRG" that achieves higher accuracy without this mode, so it doesn't use the double-speed mode.
In theory, you should be able to double the speed of the Serial port by doing something like:
USART1_CTRLB |= USART_RXMODE_CLK2X_gc;
AFTER you do the Serial1.begin().
(Be careful on other boards. There's no reason that "Serial1" has to use USART1...)
In normal use the USART divides the time space for one bit in 16 parts. With 16MHz and no prescaler (BAUD register = 1) 1,000,000 baud is achieved. Apparently the header files for the UNO R3 and MEGA allow for use of the Double Speed Mode.
The USART in the 4809 is different, it contains a Fractional Baud Rate Generator (here BAUD register = 0x40 means 1). This allows for achieving some baud rates without using Double Speed Mode that is available, but apparently can't be used with the header files provided.
typedef enum {
LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;
This results in HIGH and LOW being 1 and 0 having PinStatus as type, not int.
There is a very good book from Tom Almy called "Far Inside The Arduino: Nano Every Supplement" He covers comprehensibly all the things you can do with it.
You can get the code from his examples here
In Chapter 20 (page 95) he covers the USART
He starts by saying that this device has four USARTs two of which are hidden and must be enabled to used. He then goes onto describe each one in detail and mentions the ones that are not included in the Arduino documentation.
I think if would be money well spent to get the full lowdown on this processor, even if it does not solve your problem. At least you will know exactly why.
Esp32
Yes - isn’t it what I said ?
When calling a function with arguments, the compiler will search for the version of that function with the arguments and types you called it with.
Example:
int add(int a, int b) {
return a + b;
}
long add(long a, long b) {
return a + b;
}
If not found, the compiler will try to find a version that works after 'promoting' the variables.
