Possible bug in ADC lld
Posted: Wed Apr 25, 2018 9:26 am
given this code, with stuff deleted:
void adc_lld_start_conversion(ADCDriver *adcp) {
uint32_t mode, cr2;
adcp->adc->CR2 = grpp->cr2 | cr2;
/* ADC start by writing ADC_CR2_ADON a second time.*/
adcp->adc->CR2 = cr2;
}
and quoting from the STM32 reference manual RM0008:
Bit 0 ADON: A/D converter ON / OFF
Note: If any other bit in this register apart from ADON is changed at the same time, then
conversion is not triggered. This is to prevent triggering an erroneous conversion.
If the conversion group structure has a CR2 bit set, then the ADC won't start (ADON a second time). In many cases, that's a good thing (like the ext trigger stuff), but...
TSVREFE: Temperature sensor and VREFINT enable
SWSTART: Start conversion of regular channels
ALIGN: Data alignment
In my case, SWSTART was in my conversion group due to this article http://www.playembedded.org/blog/en/2015/02/16/sampling-and-dimming/ and ADC wasn't happening. Yes, I know that article says it's deprecated, but I figured that since it was written only a couple years ago, it should be close to still relevant.
Seems like the second CR2 assignment should match the first
Fixing this may be tricky for legacy reasons?
Miles
void adc_lld_start_conversion(ADCDriver *adcp) {
uint32_t mode, cr2;
adcp->adc->CR2 = grpp->cr2 | cr2;
/* ADC start by writing ADC_CR2_ADON a second time.*/
adcp->adc->CR2 = cr2;
}
and quoting from the STM32 reference manual RM0008:
Bit 0 ADON: A/D converter ON / OFF
Note: If any other bit in this register apart from ADON is changed at the same time, then
conversion is not triggered. This is to prevent triggering an erroneous conversion.
If the conversion group structure has a CR2 bit set, then the ADC won't start (ADON a second time). In many cases, that's a good thing (like the ext trigger stuff), but...
TSVREFE: Temperature sensor and VREFINT enable
SWSTART: Start conversion of regular channels
ALIGN: Data alignment
In my case, SWSTART was in my conversion group due to this article http://www.playembedded.org/blog/en/2015/02/16/sampling-and-dimming/ and ADC wasn't happening. Yes, I know that article says it's deprecated, but I figured that since it was written only a couple years ago, it should be close to still relevant.
Seems like the second CR2 assignment should match the first
Fixing this may be tricky for legacy reasons?
Miles