Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnalogInOutSerial max reading seems low #30

Closed
RickKimball opened this issue Jun 13, 2017 · 3 comments
Closed

AnalogInOutSerial max reading seems low #30

RickKimball opened this issue Jun 13, 2017 · 3 comments

Comments

@RickKimball
Copy link
Contributor

RickKimball commented Jun 13, 2017

I'm using the Nucleo_F030R8 branch to test out the analog features. I used an unmodified version of the AnalogInOutSerial sketch. I connected pin A0 to the 3.3V pin using a 4.9k resistor. I would expect the sensor reading to be 1023. However I'm seeing 1005.

sensor = 1005	 output = 250
sensor = 1005	 output = 250
sensor = 1006	 output = 250
sensor = 1005	 output = 250

The voltage between GND and the 3.3v pins is 3.3158v

Is there a reason this isn't reading 1023?

http:https://tinyurl.com/y6v4u6sm

@RickKimball
Copy link
Contributor Author

RickKimball commented Jun 13, 2017

FWIW: I compiled and tested the ADC demo from the STM32Cube/Repository

~/STM32Cube/Repository/STM32Cube_FW_F0_V1.8.0/Projects/STM32F030R8-Nucleo/Examples/ADC/ADC_DMA_Transfer

It returns 4095 ( it is a 12 bit resolution example ) and this is what I would expect. So it seems the hardware is capable.

@RickKimball
Copy link
Contributor Author

RickKimball commented Jun 13, 2017

If I add in a calibration routine, it now produces the full range:

sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255
sensor = 1023	 output = 255

Here is the change I made

diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c
index d4c66e5..f2735cd 100644
--- a/cores/arduino/stm32/analog.c
+++ b/cores/arduino/stm32/analog.c
@@ -611,6 +611,12 @@ uint16_t adc_read_value(PinName pin)
     /* ADC Calibration Error */
     return 0;
   }
+#elif defined (STM32F0xx)
+  if (HAL_ADCEx_Calibration_Start(&AdcHandle) !=  HAL_OK)
+  {
+    /* ADC Calibration Error */
+    return 0;
+  }
 #endif
 
   /*##-3- Start the conversion process ####################*/

@fpistm
Copy link
Member

fpistm commented Jun 14, 2017

@fpistm fpistm closed this as completed in 3299a73 Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants