2022-03-31 11:38 AM
While output data from DMA to SPI it should be able to use two buffers. One for the current transfer, one to write data.
But how do I switch between the buffers?
#define BUFFER_SIZE 10
uint8_t txBuffer[BUFFER_SIZE + BUFFER_SIZE];
HAL_SPI_Transmit_DMA(&hspi2, (uint8_t*)txBuffer, BUFFER_SIZE);
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)
{
int value = 0;
if (txBufferHalf == 0) {
for (unsigned int i = 0; i < BUFFER_SIZE; ++i) {
txBuffer[i] = ++value;
}
txBufferHalf = 1;
}
else
{
for (unsigned int i = 0; i < BUFFER_SIZE; ++i) {
txBuffer[i + BUFFER_SIZE] = ++value + 100;
}
txBufferHalf = 0;
}
}
Solved! Go to Solution.
2022-03-31 12:10 PM
Solved. Has to use both HAL_SPI_TxHalfCpltCallback and HAL_SPI_TxCpltCallback
2022-03-31 12:10 PM
Solved. Has to use both HAL_SPI_TxHalfCpltCallback and HAL_SPI_TxCpltCallback