2024-08-30 03:00 AM
This question is about HAL_SPI_TransmitReceive.
If a slave starts sending 8 bytes of data after the 4th byte sent by the master, is it possible to use HAL_SPI_TransmitReceive without a dummy (ignore) buffer?
We will be the master side.
Our assumption is that a dummy (ignore) buffer will be created.
HAL_SPI_TransmitReceive(&hspi1, sbuf, rbuf, 12, 1000)
sbuf[12] = { A, B, C, D, Dummy, Dummy, Dummy, Dummy, Dummy, Dummy, Dummy }
rbuf[12] = { Dummy, Dummy, Dummy, Dummy, A, B, C, D, E, F, G, H }
Is this perception wrong?
Solved! Go to Solution.
2024-08-30 03:30 AM
Both buffers need to be the total transaction length. They will not be created automatically. However, you can use the same buffer to transmit and receive, which will get you what you want.
uint8_t buf[12] = {A, B, C, D};
HAL_SPI_TransmitReceive(&hspi1, buf, buf, 12, HAL_MAX_DELAY)
uint8_t x = buf[5];
etc...
You could also break it up into two transactions.
uint8_t sbuf[4] = {A, B, C, D};
HAL_SPI_Transmit(&hspi1, sbuf, 4, HAL_MAX_DELAY)
uint8_t rbuf[8] = {0};
HAL_SPI_Receive(&hspi1, rbuf, 8, HAL_MAX_DELAY)
uint8_t x = rbuf[0];
etc...
2024-08-30 03:30 AM
Both buffers need to be the total transaction length. They will not be created automatically. However, you can use the same buffer to transmit and receive, which will get you what you want.
uint8_t buf[12] = {A, B, C, D};
HAL_SPI_TransmitReceive(&hspi1, buf, buf, 12, HAL_MAX_DELAY)
uint8_t x = buf[5];
etc...
You could also break it up into two transactions.
uint8_t sbuf[4] = {A, B, C, D};
HAL_SPI_Transmit(&hspi1, sbuf, 4, HAL_MAX_DELAY)
uint8_t rbuf[8] = {0};
HAL_SPI_Receive(&hspi1, rbuf, 8, HAL_MAX_DELAY)
uint8_t x = rbuf[0];
etc...
2024-08-30 03:41 AM
Thank you for your quick reply. It was extremely helpful.