0
0
Embedded Cprogramming~10 mins

Reading a hardware register 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 read the value from the hardware register.

Embedded C
volatile uint32_t value = *[1];
Drag options to blanks, or click blank then click option'
A(uint32_t *)0x40021000
B0x40021000
C&0x40021000
Duint32_t *0x40021000
Attempts:
3 left
💡 Hint
Common Mistakes
Using the address without casting to a pointer type.
Trying to take the address of a literal.
Using incorrect pointer syntax.
2fill in blank
medium

Complete the code to define a pointer to the hardware register address 0x40021004.

Embedded C
volatile uint32_t *reg = [1];
Drag options to blanks, or click blank then click option'
A&0x40021004
B0x40021004
C(uint32_t *)0x40021004
D(volatile uint32_t)0x40021004
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the address without casting.
Using the address-of operator on a literal.
Casting to the wrong type.
3fill in blank
hard

Fix the error in the code to correctly read the hardware register value.

Embedded C
uint32_t value = *[1]0x40021008;
Drag options to blanks, or click blank then click option'
A&
B(volatile uint32_t *)
C(uint32_t *)
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Dereferencing the address without casting.
Using the wrong pointer type.
Using the address-of operator incorrectly.
4fill in blank
hard

Fill both blanks to declare and read a volatile hardware register at address 0x4002100C.

Embedded C
volatile uint32_t *[1] = [2]0x4002100C;
uint32_t value = *reg;
Drag options to blanks, or click blank then click option'
Areg
B(uint32_t *)
C(volatile uint32_t *)
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pointer name.
Casting to non-volatile pointer type.
Using the address-of operator incorrectly.
5fill in blank
hard

Fill all three blanks to declare a volatile pointer, assign the hardware register address 0x40021010, and read its value.

Embedded C
volatile uint32_t *[1];
[2] = [3]0x40021010;
uint32_t value = *reg;
Drag options to blanks, or click blank then click option'
Areg
C(volatile uint32_t *)
D(uint32_t *)
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for declaration and assignment.
Casting to non-volatile pointer type.
Not casting the address before assignment.