0
0
Embedded Cprogramming~10 mins

Memory-mapped I/O concept 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 define a pointer to a memory-mapped I/O register at address 0x40021000.

Embedded C
volatile unsigned int *reg = (volatile unsigned int *)[1];
Drag options to blanks, or click blank then click option'
A0x20000000
B0x40021000
C0x60000000
D0x10000000
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect address that does not map to the desired peripheral.
2fill in blank
medium

Complete the code to write the value 0x01 to the memory-mapped register pointed by reg.

Embedded C
*reg = [1];
Drag options to blanks, or click blank then click option'
A0x10
B0xFF
C0x01
D0x00
Attempts:
3 left
💡 Hint
Common Mistakes
Writing 0x10 or 0xFF which sets other bits unintentionally.
3fill in blank
hard

Fix the error in the code to correctly read the value from the memory-mapped register.

Embedded C
unsigned int value = [1]reg;
Drag options to blanks, or click blank then click option'
A*
B&
C->
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using ® which gives the address of the pointer variable, not the register.
4fill in blank
hard

Fill both blanks to define a pointer to a volatile 8-bit register at address 0x50000010 and write 0xFF to it.

Embedded C
volatile [1] *reg8 = (volatile [2] *)0x50000010;
*reg8 = 0xFF;
Drag options to blanks, or click blank then click option'
Aunsigned char
Bunsigned int
Cchar
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unsigned int' which is typically 32-bit and incorrect for 8-bit registers.
5fill in blank
hard

Fill all three blanks to create a macro that reads a 16-bit memory-mapped register at a given address.

Embedded C
#define READ_REG16(addr) (*(volatile [1] *)[2])

unsigned short val = READ_REG16([3]);
Drag options to blanks, or click blank then click option'
Aunsigned short
B(addr)
C0x40002000
Dunsigned int
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsigned int which is 32-bit, or wrong addresses.