Skip to main content

Subsection 14.3.2 Reading Two Channels

The ADC converts the channels selected in ADC_CHSELR, one bit per channel (Figure 6.2.4). The Lab 5 library’s adc_setChannel() writes that register with a single channel’s bit, and a read that follows converts that channel. The Reference Manual adds one condition (RM0490 §14, the ADC_CR register description): after writing to ADC_CHSELR it is mandatory to wait until the CCRDY flag in ADC_ISR is set before setting ADSTART, otherwise the write to ADSTART is ignored. A channel-select function that does not wait therefore starts no conversion at all: the read that follows either blocks on EOC or returns the previous conversion’s result, which is the old channel’s. The other way to read two channels is to select both bits in ADC_CHSELR at once: in that case the sequencer converts the selected channels in increasing channel order, which is the reset configuration (CHSELRMOD = 0, SCANDIR = 0; Reference Manual §14.4.8, Channel selection), the EOC (end of conversion) flag is set after each conversion with that channel’s result in ADC_DR, and the EOS (end of sequence) flag is set after the last.