Skip to content

STM32F3 correct analogin_read #8131

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

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions targets/TARGET_STM/TARGET_STM32F3/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -211,16 +212,27 @@ uint16_t adc_read(analogin_t *obj)
return 0;
}

HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
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");;
}

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

// Wait end of conversion and get value
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
MeasuredValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
debug("HAL_ADC_PollForConversion issue\n");
}

if (HAL_ADC_Stop(&obj->handle) != HAL_OK) {
debug("HAL_ADC_Stop issue\n");;
}

return MeasuredValue;
}

#endif