File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
targets/TARGET_STM/TARGET_STM32F3 Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 34
34
#include "cmsis.h"
35
35
#include "pinmap.h"
36
36
#include "mbed_error.h"
37
+ #include "mbed_debug.h"
37
38
#include "PeripheralPins.h"
38
39
39
40
void analogin_init (analogin_t * obj , PinName pin )
@@ -211,16 +212,27 @@ uint16_t adc_read(analogin_t *obj)
211
212
return 0 ;
212
213
}
213
214
214
- HAL_ADC_ConfigChannel (& obj -> handle , & sConfig );
215
+ if (HAL_ADC_ConfigChannel (& obj -> handle , & sConfig ) != HAL_OK ) {
216
+ debug ("HAL_ADC_ConfigChannel issue\n" );;
217
+ }
218
+
219
+ if (HAL_ADC_Start (& obj -> handle ) != HAL_OK ) {
220
+ debug ("HAL_ADC_Start issue\n" );;
221
+ }
215
222
216
- HAL_ADC_Start ( & obj -> handle ); // Start conversion
223
+ uint16_t MeasuredValue = 0 ;
217
224
218
- // Wait end of conversion and get value
219
225
if (HAL_ADC_PollForConversion (& obj -> handle , 10 ) == HAL_OK ) {
220
- return (uint16_t )HAL_ADC_GetValue (& obj -> handle );
226
+ MeasuredValue = (uint16_t )HAL_ADC_GetValue (& obj -> handle );
221
227
} else {
222
- return 0 ;
228
+ debug ( "HAL_ADC_PollForConversion issue\n" ) ;
223
229
}
230
+
231
+ if (HAL_ADC_Stop (& obj -> handle ) != HAL_OK ) {
232
+ debug ("HAL_ADC_Stop issue\n" );;
233
+ }
234
+
235
+ return MeasuredValue ;
224
236
}
225
237
226
238
#endif
You can’t perform that action at this time.
0 commit comments