SM32F3 correct analogin_read

pull/8341/head
jeromecoutant 2018-09-14 10:20:24 +02:00 committed by adbridge
parent 366ad09e67
commit 7fcf9cc45c
1 changed files with 21 additions and 9 deletions

View File

@ -34,6 +34,7 @@
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "mbed_error.h" #include "mbed_error.h"
#include "mbed_debug.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
void analogin_init(analogin_t *obj, PinName pin) void analogin_init(analogin_t *obj, PinName pin)
@ -211,16 +212,27 @@ uint16_t adc_read(analogin_t *obj)
return 0; return 0;
} }
HAL_ADC_ConfigChannel(&obj->handle, &sConfig); if (HAL_ADC_ConfigChannel(&obj->handle, &sConfig) != HAL_OK) {
debug("HAL_ADC_ConfigChannel issue\n");;
HAL_ADC_Start(&obj->handle); // Start conversion
// Wait end of conversion and get value
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
} }
if (HAL_ADC_Start(&obj->handle) != HAL_OK) {
debug("HAL_ADC_Start issue\n");;
}
uint16_t MeasuredValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
MeasuredValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
debug("HAL_ADC_PollForConversion issue\n");
}
if (HAL_ADC_Stop(&obj->handle) != HAL_OK) {
debug("HAL_ADC_Stop issue\n");;
}
return MeasuredValue;
} }
#endif #endif