I'm working on a software solution which set the Pin PC2 to "reset state" if my input signal (connected to ADC) is above 2V.
I testing my code with STM32 Studio to watch in real time the digital output of my ADC.
Here is how i configured the ADC1 :
hadc3.Instance = ADC1;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV6;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.EOCSelection = DISABLE;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.NbrOfDiscConversion = 0;
hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T1_CC1;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.DMAContinuousRequests = DISABLE;
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc3.Init.OversamplingMode = DISABLE;
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
I can proper retrieve the output number of my ADC with DMA but I've an electronic problem I think :
In Nucleo STM32L476-RG, the ADC1 Channel 1 & 2 are connected to the pin PC0 and PC1.
When I connect the pin PC1 to the STM32L4 GND and the pin PC0 to the 3.3V, i can retrieve the 4095 value from the ADC, that's good.
But, when I connect the pin PC0 to GND or a 0V source, the ADC should return me 0 value but it don't, it return 1981 value.
For resume :
Input of ADC1 : 3.3V | Output of ADC1 : 4095 | Config : PC1 on GND ; PC0 on 3.3V
Input of ADC1 : 0V | Output of ADC1 : 1981 | Config : PC1 on GND ; PC0 on 0V/GND
I don't know why i've got this Offset. I've read the datasheet a thousand of times, STMicroElectronics mention a 0V Reference which called VSSA or VREF- but i don't understand how to connect my Pins.
The only pins which i use is the PC0 and PC1. Should I connect other PIN to a ground or anything? Someone had this problem before?