Created
August 3, 2023 13:27
-
-
Save DanGdl/d0b0b63246404a75d378cc0a78317fbf to your computer and use it in GitHub Desktop.
SPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void q1_SPI_ping_pong() { | |
printf("\r\n\r\n\r\nQ1 Ping pong on SPI\r\n"); | |
char message[] = "That's a SPI message"; | |
char buffer1[128] = { '\0' }; | |
char buffer2[128] = { '\0' }; | |
while(1) { | |
HAL_StatusTypeDef status = HAL_SPI_Receive_IT(SPI_S, (uint8_t*) buffer1, LEN_STR(message)); | |
if (status != HAL_OK) { | |
printf("Failed to receiveIT on SPI_S: %d, error 0x%"PRIX32"\r\n", status, HAL_SPI_GetError(SPI_S)); | |
} | |
printf("SPI_M sends message: %s\r\n", message); | |
status = HAL_SPI_Transmit(SPI_M, (uint8_t*) message, LEN_STR(message), HAL_MAX_DELAY); | |
if (status != HAL_OK) { | |
printf("Failed to send data on SPI_M: %d, error 0x%"PRIX32"\r\n", status, HAL_SPI_GetError(SPI_M)); | |
} | |
// wait till data received | |
while(!spi5_received); | |
printf("SPI_S got message: %s\r\n\r\n", buffer1); | |
status = HAL_SPI_Receive_IT(SPI_M, (uint8_t*) buffer2, LEN_STR(buffer2)); | |
if (status != HAL_OK) { | |
printf("Failed to receiveIT on SPI_M: %d, error 0x%"PRIX32"\r\n", status, HAL_SPI_GetError(SPI_M)); | |
} | |
printf("SPI_S sends message: %s\r\n", buffer1); | |
status = HAL_SPI_Transmit(SPI_S, (uint8_t*) buffer1, strlen(buffer1), HAL_MAX_DELAY); | |
if (status != HAL_OK) { | |
printf("Failed to send data on SPI_S: %d, error 0x%"PRIX32"\r\n", status, HAL_SPI_GetError(SPI_S)); | |
} | |
while(!spi1_received); | |
printf("SPI_M got message: %s\r\n\r\n", buffer2); | |
memset(buffer1, '\0', sizeof(buffer1)); | |
memset(buffer2, '\0', sizeof(buffer2)); | |
HAL_Delay(3000); | |
spi5_received = 0; | |
spi1_received = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment