Skip to content

Commit e9b9f0b

Browse files
Correctly scale analog reading per issue #4794
1 parent eefba16 commit e9b9f0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/stm/common-hal/analogio/AnalogIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
204204
uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
205205
HAL_ADC_Stop(&AdcHandle);
206206

207-
// // Shift the value to be 16 bit.
208-
return value << 4;
207+
// Stretch 12-bit ADC reading to 16-bit range
208+
return (value << 4) | (value >> 8);
209209
}
210210

211211
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

0 commit comments

Comments
 (0)