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
564 stars 148 forks source link

Serial baud rate setting differs from actual measurement on ATtiny1604. #1029

Closed 7-rate closed 1 year ago

7-rate commented 1 year ago

On ATtiny1604, I set the baud rate to 300 like Serial.begin(300);, but I could not receive properly unless I set the value on the serial monitor (TearTerm) side to 900.

hmeijdam commented 1 year ago

In a sketch with

int main(void) {
  while (1)  {
  }
}

maybe, or are you using Setup and Loop ?

[EDIT] Printing at 300 baud works on my end if I select a low clock frequency. Try clocking with 1MHz

SpenceKonde commented 1 year ago

Per the documentation both here and in the datasheet, 300 baud cannot be generated by the hardware.

https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/Ref_Serial.md#minimums

300 baud will work only when F_CPU is no higher than 5 MHz. 600 baud will work only when F_CPU is no higher than 10 MHz. 1200 baud will work as long as F_CPU is no higher than 20 MHz.

There's plenty of background explaining why in that document.