diff --git a/src/ADCSetup.cpp b/src/ADCSetup.cpp index a08a1a1..3c8c222 100644 --- a/src/ADCSetup.cpp +++ b/src/ADCSetup.cpp @@ -14,7 +14,9 @@ void ADC0Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV DACSetup(BaseV); //Setup DAC if needed }; -ADC0->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); + + ADC0->CALIB.reg = ADC_CALIB_BIASREFBUF(((*((uint32_t *) ADC0_FUSES_BIASREFBUF_ADDR) & ADC0_FUSES_BIASREFBUF_Msk) >> ADC0_FUSES_BIASREFBUF_Pos)) + | ADC_CALIB_BIASCOMP(((*((uint32_t *) ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos)); if (DacRef) { ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; @@ -129,12 +131,14 @@ void ADC1Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV DACSetup(BaseV); //Setup DAC if needed }; -ADC1->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); + + ADC1->CALIB.reg = ADC_CALIB_BIASREFBUF(((*((uint32_t *) ADC1_FUSES_BIASREFBUF_ADDR) & ADC1_FUSES_BIASREFBUF_Msk) >> ADC1_FUSES_BIASREFBUF_Pos)) + | ADC_CALIB_BIASCOMP(((*((uint32_t *) ADC1_FUSES_BIASCOMP_ADDR) & ADC1_FUSES_BIASCOMP_Msk) >> ADC1_FUSES_BIASCOMP_Pos)); if (DacRef) { - ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; + ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; } else { - ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; + ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; };