Skip to content

Commit

Permalink
STM32WB: ADC INTERNAL CHANNEL reset after read
Browse files Browse the repository at this point in the history
Internal channels use is enabling ADC "internal path" which needs
to be disabled after measurement.

Same applied here for WB family as was done for others in #10143.
  • Loading branch information
LMESTM authored and 0xc0170 committed Apr 5, 2019
1 parent defa75a commit c5b277f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions targets/TARGET_STM/TARGET_STM32WB/analogin_device.c
Expand Up @@ -190,19 +190,12 @@ uint16_t adc_read(analogin_t *obj)
}

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {

/* Ref Manual: To prevent any unwanted consumption on the battery,
it is recommended to enable the bridge divider only when needed for ADC conversion */
if (sConfig.Channel == ADC_CHANNEL_VBAT) {
CLEAR_BIT(__LL_ADC_COMMON_INSTANCE(obj->handle.Instance)->CCR, LL_ADC_PATH_INTERNAL_VBAT);
}

return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
debug("ADC conversion failed. Returned 0.\r\n");
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down

0 comments on commit c5b277f

Please sign in to comment.