0
0
Embedded Cprogramming~10 mins

ADC interrupt-driven reading in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable the ADC.

Embedded C
ADC->CR2 |= [1];
Drag options to blanks, or click blank then click option'
AADC_CR2_CONT
BADC_CR2_ADON
CADC_CR2_DMA
DADC_CR2_EOCS
Attempts:
3 left
💡 Hint
Common Mistakes
Using ADC_CR2_CONT which enables continuous mode but not interrupt.
Using ADC_CR2_DMA which enables DMA, not interrupt.
Using ADC_CR2_EOCS which configures end of conversion selection.
2fill in blank
medium

Complete the code to start the ADC conversion.

Embedded C
ADC->CR2 |= [1];
Drag options to blanks, or click blank then click option'
AADC_CR2_SWSTART
BADC_CR2_ADON
CADC_CR2_EXTTRIG
DADC_CR2_DMA
Attempts:
3 left
💡 Hint
Common Mistakes
Using ADC_CR2_ADON which only enables ADC but does not start conversion.
Using ADC_CR2_EXTTRIG which is for external trigger, not software start.
Using ADC_CR2_DMA which enables DMA, unrelated to start.
3fill in blank
hard

Fix the error in the interrupt handler to clear the ADC interrupt flag.

Embedded C
void ADC_IRQHandler(void) {
    if (ADC->SR & [1]) {
        uint16_t value = ADC->DR;
        // process value
        ADC->SR &= ~ADC_SR_EOC;
    }
}
Drag options to blanks, or click blank then click option'
AADC_SR_EOC
BADC_SR_STRT
CADC_SR_AWD
DADC_SR_OVR
Attempts:
3 left
💡 Hint
Common Mistakes
Checking ADC_SR_OVR which is overrun flag, not conversion complete.
Checking ADC_SR_AWD which is analog watchdog flag.
Checking ADC_SR_STRT which is start flag, not end.
4fill in blank
hard

Fill both blanks to configure the NVIC for ADC interrupt with priority 1.

Embedded C
NVIC_SetPriority([1], 1);
NVIC_EnableIRQ([2]);
Drag options to blanks, or click blank then click option'
AADC_IRQn
BTIM2_IRQn
CUSART1_IRQn
DEXTI0_IRQn
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated IRQ numbers like TIM2_IRQn or USART1_IRQn.
Mismatching IRQ numbers between priority and enable calls.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores ADC values for channels with readings above 1000.

Embedded C
adc_values = { [1]: [2] for [3] in channels if readings[[3]] > 1000 }
Drag options to blanks, or click blank then click option'
Achannel
Breadings[channel]
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the opening brace.
Using wrong variable names for keys or values.
Incorrect comprehension syntax.