Merge pull request #8131 from jeromecoutant/PR_F3_ADC

STM32F3 correct analogin_read
pull/8231/merge
Martin Kojtal 2018-09-25 13:24:03 +02:00 committed by GitHub
commit 65a0a1aecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 9 deletions

View File

@ -34,6 +34,7 @@
#include "cmsis.h"
#include "pinmap.h"
#include "mbed_error.h"
#include "mbed_debug.h"
#include "PeripheralPins.h"
void analogin_init(analogin_t *obj, PinName pin)
@ -211,16 +212,27 @@ uint16_t adc_read(analogin_t *obj)
return 0;
}
HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
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_ConfigChannel(&obj->handle, &sConfig) != HAL_OK) {
debug("HAL_ADC_ConfigChannel issue\n");;
}
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