Updated with info on the crystal and timing issues.w

This commit is contained in:
Jake Goodwin 2023-01-16 21:01:04 -08:00
parent 65928780d9
commit 083b95b61d
1 changed files with 22 additions and 1 deletions

View File

@ -9,6 +9,7 @@ Over time, I'm planning to add support for multiple AVR MCUs, however that
may end up requiring more memory, so extensive of use of define macros will may end up requiring more memory, so extensive of use of define macros will
likely end up being the end result. likely end up being the end result.
## Features: ## Features:
- Multiple Baud Rates: 300, 600, 1200, 2400, 9600 ... - Multiple Baud Rates: 300, 600, 1200, 2400, 9600 ...
@ -18,6 +19,7 @@ likely end up being the end result.
- Hardware abstraction API - Hardware abstraction API
- No Interrupt service routines required. - No Interrupt service routines required.
- BSD-3 Licensing, aka you can use this for whatevery you want pretty much. - BSD-3 Licensing, aka you can use this for whatevery you want pretty much.
- Runtime configuration of serial settings.
@ -49,6 +51,10 @@ void echo_char(char* cmd) {
} }
int main() { int main() {
usart0_init();
serial0_enable_parity_bit(2); //odd parity
sei(); //enable interrupts, not needed right now.
while(1) { while(1) {
echo_char(); echo_char();
} }
@ -62,5 +68,20 @@ int main() {
It's required to set the fuses in the chip for 8Mhz, otherwise a baud rate It's required to set the fuses in the chip for 8Mhz, otherwise a baud rate
of 9600 will result in errors at a 7% rate. of 9600 will result in errors at a 7% rate.
Another is that I need to design a standard naming scheme. ### Internal Crystal
The internal crystal oscillator can have up too 10% variation. This doesn't
seem like a lot, but it makes a huge differnce.
for one of the Atmega 328p MCUs I tested it woul return garbage data to a
a serial terminal at 8-N-1 4800 baud.
when I set the usb to serial adapter too 7-N-1 I would stop having issues
suddenly.
going back to 8-N-1 on the usb to serial adapter and then changing it's baud
rate too 4825 totally fixed the issue. This told me that the crystal that
the 328p was clocking off of was faster than it should be.
TLDR; You should really use a decent external clock for async serial otherwise
you are going to have a bad time.