Hi Giovanni,
and thanks for your reply.
I tried to follow your suggestion and I wrote this simple code for testing:
Code: Select all
#include "ch.h"
#include "hal.h"
#define ADC_NUM_CHANNELS 1
#define ADC_BUF_DEPTH 128
static adcsample_t ADCsamples[ADC_NUM_CHANNELS*ADC_BUF_DEPTH] = {0};
static uint32_t average = 0;
static const ADCConversionGroup adcgrpcfg =
{
FALSE,
ADC_NUM_CHANNELS,
NULL,
NULL,
ADC_CFGR1_RES_12BIT, /* CFGR */
ADC_TR(0, 4095), /* TR1 */
ADC_CCR_CKMODE_ADCCK, /* CCR */
{ /* SMPR[2] */
ADC_SMPR1_SMP_AN2(ADC_SMPR_SMP_1P5),
0
},
{ /* SQR[4] */
ADC_SQR1_SQ1_N(ADC_CHANNEL_IN2),
0,
0,
0
}
};
int main(void)
{
int i = 0;
halInit();
chSysInit();
palSetGroupMode(GPIOA, PAL_PORT_BIT(1) | PAL_PORT_BIT(2), 0, PAL_MODE_INPUT_ANALOG);
adcStart(&ADCD1, NULL);
ADC1->DIFSEL = ADC_DIFSEL_DIFSEL_1;
adcConvert(&ADCD1, &adcgrpcfg, &ADCsamples[0], ADC_BUF_DEPTH);
for (i = 0; i < ADC_BUF_DEPTH; i++)
{
average = average + ADCsamples[i];
}
average = average/ADC_BUF_DEPTH;
while (TRUE)
{
chThdSleepMilliseconds(1);
}
return 0;
}
I expected to be able to convert the voltage drop between pins PA1 (channel 2 of ADC1) and PA2 (channel 2 of ADC1), but it does not work. It just converts the voltage drop between pins PA1 and GND, as in single-ended mode. I tried to move the DIFSEL setting before "adcStart", but with the same result.
Have you any idea about what can be wrong? Is the way I set DIFSEL right? (building the project does not return any error or warning)
Thank you in advance...