cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear internal SPI TX buffer in slave mode after transaction cancellation? SPI used in slave mode with DMA circular buffer.

Evgeny Sobolev
Associate III

Hello. I am using STM32F407VG controller. I have to transfer data from another device via SPI interface. STM32 SPI is used in slave mode, circular DMA enabled. Devices are connected via joint.

In some cases I need to resynchronize data exchange. At this moment SPI master device stops data exchange for some time (clock is stopped, CS is high). SPI slave (STM32F407VG) after some time tried to stop SPI  (HAL_SPI_Abort(&hspi1); ) and then restart SPI with circular DMA again. 

But after this operation other side (SPI master) receive one unnecessary byte. This byte have been transferred by DMA to SPI TX buffer before transaction is stopped. How to remove this byte from SPI TX buffer before start transaction. I tried to disable SPI, disable SPI pheripheral clock, but nothing help.

I have an idea to disable GPIO and switch SPI to master mode. Is there another way possible? May be unreferenced register to reset spi buffer or spi module exists.

11 REPLIES 11

Thank you for saving my day!

RusikOk
Associate III

hi! on the M0 + core, it worked for me only like this:

        HAL_SPI_DMAStop(&hspi1);
        __HAL_RCC_SPI1_FORCE_RESET();
        __HAL_RCC_SPI1_RELEASE_RESET();
        MX_SPI1_Init();