How to switch the DMA buffer in HAL_SPI_Transmit_DMA
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
Labels:
- Labels:
-
DMA
-
SPI
-
STM32Cube MCU Packages
This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION
Accepted Solutions
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-03-31 12:10 PM
Solved. Has to use both HAL_SPI_TxHalfCpltCallback and HAL_SPI_TxCpltCallback
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-03-31 12:10 PM
Solved. Has to use both HAL_SPI_TxHalfCpltCallback and HAL_SPI_TxCpltCallback
