Skip to content

Commit 52776a1

Browse files
committed
SM32F3 correct analogin_read
1 parent 2e5e23f commit 52776a1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

targets/TARGET_STM/TARGET_STM32F3/analogin_device.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "cmsis.h"
3535
#include "pinmap.h"
3636
#include "mbed_error.h"
37+
#include "mbed_debug.h"
3738
#include "PeripheralPins.h"
3839

3940
void analogin_init(analogin_t *obj, PinName pin)
@@ -211,16 +212,27 @@ uint16_t adc_read(analogin_t *obj)
211212
return 0;
212213
}
213214

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+
}
215222

216-
HAL_ADC_Start(&obj->handle); // Start conversion
223+
uint16_t MeasuredValue = 0;
217224

218-
// Wait end of conversion and get value
219225
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);
221227
} else {
222-
return 0;
228+
debug("HAL_ADC_PollForConversion issue\n");
223229
}
230+
231+
if (HAL_ADC_Stop(&obj->handle) != HAL_OK) {
232+
debug("HAL_ADC_Stop issue\n");;
233+
}
234+
235+
return MeasuredValue;
224236
}
225237

226238
#endif

0 commit comments

Comments
 (0)