0
0
Embedded Cprogramming~10 mins

SPI master-slave architecture 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 initialize SPI as master.

Embedded C
SPI_InitTypeDef SPI_Config;
SPI_Config.Mode = [1];
// Other configurations follow
Drag options to blanks, or click blank then click option'
ASPI_MODE_MASTER
BSPI_MODE_SLAVE
CSPI_MODE_BIDIRECTIONAL
DSPI_MODE_SIMPLEX
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing slave mode instead of master mode.
2fill in blank
medium

Complete the code to set the SPI clock polarity to idle low.

Embedded C
SPI_Config.CLKPolarity = [1];
Drag options to blanks, or click blank then click option'
ASPI_POLARITY_LOW
BSPI_POLARITY_HIGH
CSPI_POLARITY_IDLE_HIGH
DSPI_POLARITY_IDLE_LOW
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing polarity high with idle low.
3fill in blank
hard

Fix the error in the SPI data size configuration.

Embedded C
SPI_Config.DataSize = [1];
Drag options to blanks, or click blank then click option'
ASPI_DATASIZE_4BIT
BSPI_DATASIZE_16BIT
CSPI_DATASIZE_32BIT
DSPI_DATASIZE_8BIT
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsupported data sizes like 32-bit or 4-bit.
4fill in blank
hard

Fill both blanks to configure SPI clock phase and NSS management.

Embedded C
SPI_Config.CLKPhase = [1];
SPI_Config.NSS = [2];
Drag options to blanks, or click blank then click option'
ASPI_PHASE_1EDGE
BSPI_PHASE_2EDGE
CSPI_NSS_SOFT
DSPI_NSS_HARD_INPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing clock phase edges or using hardware NSS when software is needed.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping SPI pins to their functions.

Embedded C
const char* SPI_Pins[] = {"MOSI", "MISO", "SCK"};
const int PinNumbers[] = [1], [2], [3];
Drag options to blanks, or click blank then click option'
A7
B6
C5
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up pin numbers or using pins not assigned to SPI.