0
0
Embedded Cprogramming~10 mins

Low-power design patterns 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 enter low-power sleep mode.

Embedded C
void enter_sleep_mode() {
    __[1]();
}
Drag options to blanks, or click blank then click option'
AWFI
BNOP
CSVC
DWFE
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOP does not put the CPU to sleep.
Using SVC triggers a supervisor call, not sleep.
WFE waits for an event, but WFI is more common for sleep.
2fill in blank
medium

Complete the code to disable the peripheral clock to save power.

Embedded C
void disable_peripheral_clock() {
    RCC->APB1ENR &= ~[1];
}
Drag options to blanks, or click blank then click option'
ARCC_APB1ENR_TIM2EN
BRCC_APB1ENR_I2C1EN
CRCC_APB1ENR_USART1EN
DRCC_APB1ENR_SPI2EN
Attempts:
3 left
💡 Hint
Common Mistakes
Disabling the wrong peripheral clock.
Using the wrong register bit mask.
3fill in blank
hard

Fix the error in the code to correctly configure the microcontroller to enter STOP mode.

Embedded C
void enter_stop_mode() {
    PWR->CR |= PWR_CR_LPDS;
    PWR->CR &= ~[1];
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    __WFI();
}
Drag options to blanks, or click blank then click option'
APWR_CR_ULP
BPWR_CR_CWUF
CPWR_CR_LPSDSR
DPWR_CR_PDDS
Attempts:
3 left
💡 Hint
Common Mistakes
Clearing the wrong bit causes the MCU to enter STANDBY mode.
Not setting SLEEPDEEP bit prevents deep sleep.
4fill in blank
hard

Complete the code to create a dictionary comprehension that maps sensor names to their power states only if the sensor is active.

Embedded C
sensor_power = {name: state for name, state in sensors.items() if state [1] 1}
Drag options to blanks, or click blank then click option'
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Adding an operator after state in the value expression.
Using != or > instead of == in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps device IDs (uppercase) to their power levels only if the level is above zero.

Embedded C
power_levels = [1]: [2] for id, level in devices.items() if level [3] 0}
Drag options to blanks, or click blank then click option'
Aid.upper()
Blevel
C>
Did.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using id.lower() instead of uppercase.
Using < or == instead of >.
Swapping keys and values in the comprehension.