0
0
Embedded Cprogramming~10 mins

SPI vs UART trade-offs in Embedded C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize SPI communication with the correct clock polarity.

Embedded C
SPI_InitTypeDef SPI_InitStruct = {0};
SPI_InitStruct.ClockPolarity = [1];
// Other initialization code
Drag options to blanks, or click blank then click option'
AUART_STOPBITS_1
BSPI_POLARITY_HIGH
CUART_PARITY_NONE
DSPI_POLARITY_LOW
Attempts:
3 left
💡 Hint
Common Mistakes
Using UART constants instead of SPI constants for clock polarity.
2fill in blank
medium

Complete the code to send a byte over UART.

Embedded C
HAL_UART_Transmit(&huart1, &[1], 1, 1000);
Drag options to blanks, or click blank then click option'
Atx_byte
Bdata
Cspi_data
Dbuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Using SPI variable names instead of UART data variable.
3fill in blank
hard

Fix the error in the SPI data reception code by completing the blank.

Embedded C
HAL_SPI_Receive(&hspi2, [1], 1, 1000);
Drag options to blanks, or click blank then click option'
A&rx_buffer
Brx_buffer
C&tx_buffer
Dtx_buffer
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the buffer variable without '&' causing runtime errors.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters SPI data bytes greater than 128.

Embedded C
filtered_data = {byte: [1] for byte in spi_data if byte [2] 128}
Drag options to blanks, or click blank then click option'
Abyte * 2
Bbyte + 1
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator or incorrect value expression.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps UART characters to their ASCII codes if code is less than 100.

Embedded C
ascii_map = [1]: ord([2]) for [3] in uart_chars if ord(char) < 100
Drag options to blanks, or click blank then click option'
Achar
Dcode
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.