SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
557 stars 145 forks source link

UART baudrate #284

Closed andcell closed 3 years ago

andcell commented 3 years ago

Hello,

the baudrate minimum value is 2400bps@20MHz clock, internal (i need 300bps). If i choose a lower value the UART don't work on ATtiny404. at different values of clock the baurates are totally wrong. Could you help me, please?

thank you. Andrea

SpenceKonde commented 3 years ago

That is correct; the USART hardware in the "modern" AVRs (that is, tinyAVR 0/1/2-series, megaAVR 0-series, and AVR Dx-series) has new "fractional baud generator" - this vastly improves the possible baud rate accuracy at high baud rates - but it comes at the cost of the minimum baud rate being 4 times higher for a given system clock. This spreadsheet shows the achievable baud rates on "modern" and "classic" AVR devices; you can see how much better the baud rate accuracy is at higher baud rates.

https://drive.google.com/file/d/1xszDrr9pD9FcKedqMCcb_GMc14Gofy-R/view?usp=sharing

If you must use slower baud rates, you must either reduce the system clock speed (for 300 baud, all system clock speeds higher than 5 MHz (at least among speeds supported by megaTinyCore), or resort to SoftwareSerial.