0
0
Embedded Cprogramming~10 mins

SPI data transfer sequence 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 the SPI data transfer by enabling the SPI peripheral.

Embedded C
SPI->[1] |= SPI_CR1_SPE;
Drag options to blanks, or click blank then click option'
ACR1
BDR
CSR
DCR2
Attempts:
3 left
💡 Hint
Common Mistakes
Using data register (DR) instead of control register.
Trying to enable SPI in status register (SR).
2fill in blank
medium

Complete the code to wait until the SPI transmit buffer is empty before sending data.

Embedded C
while (!(SPI->SR & [1]));
Drag options to blanks, or click blank then click option'
ASPI_SR_TXE
BSPI_SR_BSY
CSPI_SR_OVR
DSPI_SR_RXNE
Attempts:
3 left
💡 Hint
Common Mistakes
Waiting for RXNE (receive buffer not empty) instead of TXE.
Checking BSY flag incorrectly.
3fill in blank
hard

Fix the error in the code that writes data to the SPI data register.

Embedded C
SPI->[1] = data;
Drag options to blanks, or click blank then click option'
ASR
BCR2
CCR1
DDR
Attempts:
3 left
💡 Hint
Common Mistakes
Writing data to control or status registers instead of data register.
4fill in blank
hard

Fill both blanks to check if SPI is busy and wait until it is free before disabling it.

Embedded C
while (SPI->SR & [1]) {} 
SPI->[2] &= ~SPI_CR1_SPE;
Drag options to blanks, or click blank then click option'
ASPI_SR_BSY
BSPI_SR_TXE
CCR1
DDR
Attempts:
3 left
💡 Hint
Common Mistakes
Checking wrong flags or disabling SPI in wrong register.
5fill in blank
hard

Fill all three blanks to create a function that sends a byte over SPI and waits for completion.

Embedded C
void SPI_SendByte(uint8_t data) {
    while (!(SPI->SR & [1]));
    SPI->[2] = data;
    while (SPI->SR & [3]) {}
}
Drag options to blanks, or click blank then click option'
ASPI_SR_TXE
BDR
CSPI_SR_BSY
DCR1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong flags or registers in the function.