I want to send some data to Atmega328PB over UART. The chip runs off the internal 8Mhz oscillator.
What are the baud rates, if any, that can work reliably given that the oscillator itself is not accurate, the voltage on 328 also is changing (works off 2 AA cells) and temperature too changes?
Subject is Atmega328pb, right?
welp, I guess the online baud rate calculator is gone. Here is a sip of some Python
bps_list =[9600, 38400, 115200, 125000] #BAUD_RATE
fcpu =8000000 #F_CPU
def baud_setting(fcpu, bps):
return int( ((fcpu + bps * 4) / (bps * 8)) - 1 )
def baud_actual(fcpu, bps):
return ( (fcpu/(8 * (baud_setting(fcpu, bps)+1))) )
def baud_error(fcpu, bps):
return ( (( 100*(bps - baud_actual(fcpu, bps)) ) / bps) )
for bps in bps_list:
print("BAUD_SETTING:%i ACTUAL:%f ERROR:%f" % (baud_setting(fcpu, bps), baud_actual(fcpu, bps), baud_error(fcpu, bps)))
input("Any key won't work you have to Enter to exit, a deep thought ;)")
BAUD_SETTING:103 ACTUAL:9615.384615 ERROR:-0.160256
BAUD_SETTING:25 ACTUAL:38461.538462 ERROR:-0.160256
BAUD_SETTING:8 ACTUAL:111111.111111 ERROR:3.549383
BAUD_SETTING:7 ACTUAL:125000.000000 ERROR:0.000000
Any key won't work you have to Enter to exit, a deep thought ;)
Moral of the story is that 38400 and 9600 bps are good, but 125k bps is a little better. The RC oscillator drift might be OK after user calibration.