SPI MISO shifted
Hello ST Community,
I have setup a SPI master and a SPI slave, both use DMA in Normal mode. The word size is 8-bits and the data size is 8-bytes. The problem is that the slave transmits messages which contains old data.
When it should send:
MISO: { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }
it sends:
MISO: { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01 }
When it should send:
MISO: { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }
it sends:
MISO: { 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02 }

OBS: The debug gpio is toggled when the ISR finishes and when theTxBuffer is edited in main.
This pattern continues for every transfer it contains 3 old bytes.
Implementation (slave):
The slave updates the response in the main function.
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
HAL_SPI_TransmitReceive_DMA(&hspi1, TxBuffer, RxBuffer, 8);
while (1)
{
if(msgReceived == 1) {
memset(TxBuffer, SPI_Counter, BUFFERSIZE);
HAL_SPI_TransmitReceive_DMA(&hspi1, TxBuffer, RxBuffer, BUFFERSIZE); // update SPI transfer
msgReceived = 0;
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_1); // DEBUG
}
}
}
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
msgReceived = 1;
SPI_Counter++;
HAL_SPI_TransmitReceive_DMA(&hspi1, TxBuffer, RxBuffer, 8); // setup a new transfer
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_1); // DEBUG
}
Setup:
Setup
How can it be that the MISO transfer contains old data?
