Skip to content

Commit 3912d9d

Browse files
Claudio Indellicaticmaglie
authored andcommitted
Loaded ADC calibration values at startup.
1 parent e3a367f commit 3912d9d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cores/arduino/startup.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ void SystemInit( void )
343343
PM->APBCSEL.reg = PM_APBCSEL_APBCDIV_DIV1_Val ;
344344

345345
SystemCoreClock=VARIANT_MCK ;
346+
347+
/* ----------------------------------------------------------------------------------------------
348+
* 8) Load ADC factory calibration values
349+
*/
350+
351+
// ADC Bias Calibration
352+
uint32_t bias = (*((uint32_t *) ADC_FUSES_BIASCAL_ADDR) & ADC_FUSES_BIASCAL_Msk) >> ADC_FUSES_BIASCAL_Pos;
353+
354+
// ADC Linearity bits 4:0
355+
uint32_t linearity = (*((uint32_t *) ADC_FUSES_LINEARITY_0_ADDR) & ADC_FUSES_LINEARITY_0_Msk) >> ADC_FUSES_LINEARITY_0_Pos;
356+
357+
// ADC Linearity bits 7:5
358+
linearity |= ((*((uint32_t *) ADC_FUSES_LINEARITY_1_ADDR) & ADC_FUSES_LINEARITY_1_Msk) >> ADC_FUSES_LINEARITY_1_Pos) << 5;
359+
360+
ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);
346361
}
347362

348363
/**

0 commit comments

Comments
 (0)