Skip to content

Commit e7a0b8a

Browse files
agdlfacchinm
authored andcommitted
Fixed baud rate issue
Move SIGROW compensation from system-wide to UART-specific Use the correct formula to calculate baud divider based on datasheet
1 parent b6c145b commit e7a0b8a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Diff for: cores/arduino/UART.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ void UartClass::begin(unsigned long baud, uint16_t config)
160160
error = 1;
161161
}
162162

163-
// ********Check if desired baud rate is within the acceptable range for using normal RX-mode********
164-
// Condition from datasheet
165-
// This limits the minimum baud_setting value to 64 (0x0040)
163+
// ********Check if desired baud rate is within the acceptable range for using normal RX-mode********
164+
// Condition from datasheet
165+
// This limits the minimum baud_setting value to 64 (0x0040)
166166
} else if ((16 * baud <= F_CPU_CORRECTED)) {
167167

168168
// Check that the desired baud rate is not so low that it will
@@ -195,6 +195,10 @@ void UartClass::begin(unsigned long baud, uint16_t config)
195195
digitalWrite(_hwserial_tx_pin, HIGH);
196196
pinMode(_hwserial_tx_pin, OUTPUT);
197197

198+
int8_t sigrow_val = SIGROW.OSC16ERR5V;
199+
baud_setting *= (1024 + sigrow_val);
200+
baud_setting /= 1024;
201+
198202
// assign the baud_setting, a.k.a. BAUD (USART Baud Rate Register)
199203
(*_hwserial_module).BAUD = (int16_t) baud_setting;
200204

Diff for: cores/arduino/wiring.c

-8
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,6 @@ void init()
313313
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 0x00);
314314
#endif
315315

316-
317-
#if (PERFORM_SIGROW_CORRECTION_F_CPU == 1)
318-
/* Calculate actual F_CPU with error values from signature row */
319-
int8_t sigrow_val = SIGROW.OSC16ERR5V;
320-
cpu_freq *= (1024 + sigrow_val);
321-
cpu_freq /= 1024;
322-
#endif /* (CORRECT_F_CPU == 1) */
323-
324316
/* Apply calculated value to F_CPU_CORRECTED */
325317
F_CPU_CORRECTED = (uint32_t)cpu_freq;
326318

0 commit comments

Comments
 (0)