Skip to content

Commit 0eaf5f6

Browse files
CopilotAlexDev404
andcommitted
Switch to 9600 baud for maximum RC oscillator tolerance
Co-authored-by: AlexDev404 <34188635+AlexDev404@users.noreply.github.com>
1 parent a4a02f3 commit 0eaf5f6

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/reference/quickstart-sim.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
```
88

99
```
10-
avrdude -CC:\Users\Immanuel\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b19200 -D -Uflash:w:C:\Data\zilog\XP_F082A_uART\src\reference\Test.BareMinimum.ino.hex:i
10+
avrdude -CC:\Users\Immanuel\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b9600 -D -Uflash:w:C:\Data\zilog\XP_F082A_uART\src\reference\Test.BareMinimum.ino.hex:i
1111
```
1212

1313
# To test (non-spoofed)
@@ -19,14 +19,15 @@ avrdude -CC:\Users\Immanuel\AppData\Local\Arduino15\packages\arduino\tools\avrdu
1919
```
2020

2121
```
22-
avrdude -CC:\Data\zilog\XP_F082A_uART\src\avrdude.conf -v -pz8f081a_no_nvds -carduino -PCOM5 -b19200 -D -Uflash:w:C:\Data\zilog\XP_F082A_uART\src\reference\Test.BareMinimum.ino.hex:i
22+
avrdude -CC:\Data\zilog\XP_F082A_uART\src\avrdude.conf -v -pz8f081a_no_nvds -carduino -PCOM5 -b9600 -D -Uflash:w:C:\Data\zilog\XP_F082A_uART\src\reference\Test.BareMinimum.ino.hex:i
2323
```
2424

2525
# Notes
2626

27-
- The bootloader uses **19200 baud** for better tolerance with the Z8F082A internal RC oscillator
28-
- Use `-b19200` with avrdude to match the bootloader baud rate
27+
- The bootloader uses **9600 baud** for maximum tolerance with the Z8F082A internal RC oscillator
28+
- Use `-b9600` with avrdude to match the bootloader baud rate
2929
- If you still get sync errors with random garbage (0xXX responses), verify:
3030
1. TX/RX are connected correctly (RX→TX, TX→RX)
3131
2. CTS is connected if required by your FTDI adapter
32-
3. The chip's internal oscillator is configured (init_systemclock() is called)
32+
3. The chip's internal oscillator is configured (init_systemclock() is called)
33+
4. Power supply is stable (3.3V)

src/uart.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
* UART Baud Rate Configuration for Z8F082A
99
*
1010
* The Z8F082A internal RC oscillator varies between parts (~5.5 MHz typical).
11-
* Using 19200 baud provides better tolerance for clock variation than 115200.
11+
* Using 9600 baud provides the BEST tolerance for clock variation.
1212
*
1313
* IMPORTANT: avrdude command must specify matching baud rate:
14-
* avrdude -c stk500v1 -b 19200 -P /dev/ttyUSB0 ...
14+
* avrdude -c stk500v1 -b 9600 -P COM3 ...
1515
*
16-
* Clock Frequency Options:
17-
* 5.5296 MHz (Internal RC): BRG = 18 for 19200 baud (exact)
18-
* 18.432 MHz (Crystal): BRG = 60 for 19200 baud (exact)
19-
* 20.0 MHz (Crystal): BRG = 65 for 19200 baud (0.16% error)
16+
* Clock Frequency Options (BRG values for 9600 baud):
17+
* 5.5296 MHz (Internal RC): BRG = 36 for 9600 baud (exact)
18+
* 18.432 MHz (Crystal): BRG = 120 for 9600 baud (exact)
19+
* 20.0 MHz (Crystal): BRG = 130 for 9600 baud (0.16% error)
2020
*/
2121

2222
/* System clock frequency - adjust to match your actual oscillator */
2323
#define SYSTEM_CLOCK_HZ 5529600UL /* 5.5296 MHz internal oscillator */
2424

25-
/* Baud rate - using 19200 for better tolerance with RC oscillator */
26-
#define BAUD_RATE 19200UL
25+
/* Baud rate - using 9600 for MAXIMUM tolerance with RC oscillator variation */
26+
#define BAUD_RATE 9600UL
2727

2828
/* Calculate baud rate divisor: BRG = (freq + baud*8) / (baud * 16) */
2929
#define BRG_VALUE ((SYSTEM_CLOCK_HZ + BAUD_RATE * 8UL) / (BAUD_RATE * 16UL))
3030

3131
void init_uart0(void)
3232
{
3333
/* Initialize UART0 for STK500 communication
34-
* BRG = (5529600 + 19200*8) / (19200*16) = 5683200 / 307200 = 18
35-
* Actual baud = 5529600 / (16 * 18) = 19200 (exact!)
34+
* BRG = (5529600 + 9600*8) / (9600*16) = 5606400 / 153600 = 36
35+
* Actual baud = 5529600 / (16 * 36) = 9600 (exact!)
3636
*/
3737

3838
/* Set baud rate generator */

0 commit comments

Comments
 (0)