Consider the following ADC interrupt handler code snippet. What value will adc_value hold after the interrupt?
volatile uint16_t adc_value = 0; void ADC_IRQHandler(void) { if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) { adc_value = ADC_GetConversionValue(ADC1); ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); } } // Assume ADC_GetConversionValue(ADC1) returns 1234 when called.
Think about what happens inside the interrupt when the end of conversion flag is set.
The interrupt handler checks if the ADC end of conversion (EOC) flag is set. If yes, it reads the conversion value (which is 1234) and stores it in adc_value. Then it clears the interrupt flag. So adc_value becomes 1234.
Choose the best description of how ADC interrupt-driven reading works in embedded systems.
Think about how interrupts help the CPU avoid waiting actively.
In interrupt-driven ADC reading, the ADC hardware triggers an interrupt when the conversion finishes. This lets the CPU do other tasks and respond only when data is ready.
Examine the code below. The adc_value variable never updates after ADC conversions. What is the likely cause?
uint16_t adc_value;
void ADC_IRQHandler(void) {
if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) {
uint16_t value = ADC_GetConversionValue(ADC1);
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
}
}
// adc_value is expected to hold the latest ADC reading.Check if the variable that stores the ADC result is updated.
The handler reads the ADC value into a local variable value but never assigns it to the global adc_value. So adc_value remains unchanged.
Given the following code snippet, which option correctly enables the ADC interrupt?
void ADC_Config(void) {
ADC_InitTypeDef ADC_InitStructure;
// ADC initialization code here
// Enable ADC interrupt
// ???
}Check the correct order and parameters for enabling ADC interrupts.
The function ADC_ITConfig takes the ADC peripheral, the interrupt type, and ENABLE or DISABLE. Option A uses the correct order and parameters.
Consider this code that uses an interrupt to read ADC values into a buffer of size 4. How many valid readings will adc_buffer contain after 6 ADC conversions?
volatile uint16_t adc_buffer[4]; volatile uint8_t index = 0; void ADC_IRQHandler(void) { if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) { adc_buffer[index++] = ADC_GetConversionValue(ADC1); if (index >= 4) { index = 0; } ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); } } // Assume 6 ADC conversions complete, each triggering the interrupt.
Think about how the index variable cycles through the buffer size.
The buffer size is 4. After 4 readings, the index resets to 0, so the next 2 readings overwrite the first 2. The buffer always holds the last 4 readings.