0
0
Embedded Cprogramming~10 mins

DMA with ADC for continuous sampling 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 start ADC conversion with DMA.

Embedded C
HAL_ADC_Start_DMA(&hadc1, [1], 1);
Drag options to blanks, or click blank then click option'
A*adc_buffer
B(uint32_t*)adc_buffer
Cadc_buffer
D&adc_buffer
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the buffer without casting to pointer type.
Passing the buffer address without proper type casting.
2fill in blank
medium

Complete the code to configure ADC for continuous conversion mode.

Embedded C
hadc1.Init.ContinuousConvMode = [1];
Drag options to blanks, or click blank then click option'
ADISABLE
BTRUE
CFALSE
DENABLE
Attempts:
3 left
💡 Hint
Common Mistakes
Setting continuous mode to DISABLE causes single conversion only.
Using boolean TRUE/FALSE instead of ENABLE/DISABLE macros.
3fill in blank
hard

Fix the error in the DMA initialization for circular mode.

Embedded C
hdma_adc1.Init.Mode = [1];
Drag options to blanks, or click blank then click option'
ADMA_CIRCULAR
BDMA_NORMAL
CDMA_PINGPONG
DDMA_SINGLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DMA_NORMAL causes DMA to stop after one transfer.
Using unsupported DMA modes like DMA_PINGPONG or DMA_SINGLE.
4fill in blank
hard

Fill both blanks to complete the ADC DMA interrupt handler.

Embedded C
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
    if(hadc->Instance == [1]) {
        process_data([2]);
    }
}
Drag options to blanks, or click blank then click option'
AADC1
BADC2
Cadc_buffer
Ddma_buffer
Attempts:
3 left
💡 Hint
Common Mistakes
Checking wrong ADC instance in the callback.
Passing wrong buffer variable to the processing function.
5fill in blank
hard

Fill all three blanks to define a DMA buffer and start ADC with DMA.

Embedded C
uint16_t [1][[2]];

int main(void) {
    HAL_Init();
    SystemClock_Config();
    MX_DMA_Init();
    MX_ADC1_Init();

    HAL_ADC_Start_DMA(&hadc1, (uint32_t*)[1], [2]);

    while(1) {
        // main loop
    }
}
Drag options to blanks, or click blank then click option'
Aadc_buffer
B128
C256
Dbuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between buffer name in declaration and DMA start.
Using incorrect buffer size for DMA transfer.