@KurtE
Quote Originally Posted by KurtE
First fix attempt:
Code:
ADC1_CFG = mode;
ADC2_CFG = mode1;
That appears to work, so I pushed the change up to github cores
@Paul - if you are looking it is in my currently pending PR in cores: https://github.com/PaulStoffregen/cores/pull/404
Nice catch and thanks for correcting. Checked Analog Resolution function to make sure that didn't have the same problem, but that was set up a bit differently so its ok.

Think there is a minor error in the analog init function as well, last few lines for ADC2:
Code:
	//ADC2
	ADC2_CFG = mode | ADC_HC_AIEN | ADC_CFG_ADHSC;
	ADC2_GC = avg | ADC_GC_CAL;		// begin cal
	calibrating = 1;
	while (ADC1_GC & ADC_GC_CAL) ;
	calibrating = 0;
Line is read probably should be:
Code:
while (ADC2_GC & ADC_GC_CAL) ;
To avoid issuing a second PR for analog.c maybe you can incorporate into your PR?

But that leads to another question with the wait_for_cal function. Right now its only setup for ADC1:
Code:
static void wait_for_cal(void)
{
	//printf("wait_for_cal\n");
	while (ADC1_GC & ADC_GC_CAL) ;
	// TODO: check CALF, but what do to about CAL failure?
	calibrating = 0;
	//printf("cal complete\n");
}
Technically shouldn't it also include ADC2:
Code:
static void wait_for_cal(void)
{
	//printf("wait_for_cal\n");
	while (ADC1_GC & ADC_GC_CAL) ;
	// TODO: check CALF, but what do to about CAL failure?
	calibrating = 0;
	while (ADC2_GC & ADC_GC_CAL) ;
	calibrating = 0;
	//printf("cal complete\n");
}
Red lines are added.