0
0
Embedded Cprogramming~10 mins

Clock polarity and phase (CPOL, CPHA) 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 set the clock polarity (CPOL) bit to 1.

Embedded C
SPI->CR1 |= (1 << [1]);
Drag options to blanks, or click blank then click option'
A2
B1
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using bit 0 instead of bit 1 for CPOL.
Confusing CPOL with CPHA bit positions.
2fill in blank
medium

Complete the code to clear the clock phase (CPHA) bit.

Embedded C
SPI->CR1 &= ~(1 << [1]);
Drag options to blanks, or click blank then click option'
A3
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Clearing the wrong bit position.
Using |= instead of &=~ to clear the bit.
3fill in blank
hard

Fix the error in the code to set CPOL and CPHA correctly.

Embedded C
SPI->CR1 = (1 << [1]) | (1 << [2]);
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Setting wrong bit positions for CPOL or CPHA.
Using assignment instead of bitwise OR.
4fill in blank
hard

Fill both blanks to configure SPI with CPOL=1 and CPHA=0 using bitwise operations.

Embedded C
SPI->CR1 = (1 << [1]) & ~(1 << [2]);
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of AND to clear a bit.
Mixing up CPOL and CPHA bit positions.
5fill in blank
hard

Fill all three blanks to create a mask that sets CPOL and CPHA bits and clears bit 2.

Embedded C
SPI->CR1 = ((1 << [1]) | (1 << [2])) & ~(1 << [3]);
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Not using parentheses causing wrong bitwise precedence.
Setting bit 2 instead of clearing it.