Skip to main content
daniel2399
Visitor II
September 25, 2014
Question

STM32L051 SPI Slave DMA - last byte duplicated & doesn't terminate

  • September 25, 2014
  • 1 reply
  • 730 views
Posted on September 26, 2014 at 00:26

Hi,

I have a problem with a SPI data transfer with DMA. I use a STM32L051 as SPI slave and created the code with STM32CubeMX.

I used the sample code as a reference and do something like this:

if (HAL_SPI_TransmitReceive_DMA(&hspi1, &txb, &rxb, 5) != HAL_OK)

{

/* Transfer error in transmission process */

}

while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)

{

HAL_Delay(1);

The transfer never completes (HAL_SPI_GetState always returns busy). The bytes are transmitted to the SPI master but the last byte is wrong (duplicated from the byte before).

Before that I transfer a single byte (with the blocking function not with DMA) and that works. I also tried to use the blocking HAL function instead of the DMA version for transmitting the 5 bytes above but it also will not terminate.

I've spent hours on that, any ideas anyone?

Danny
    This topic has been closed for replies.

    1 reply

    Montassar BEN ROMDHANE_O
    Visitor II
    September 26, 2014
    Posted on September 26, 2014 at 11:42

    HiDanny,

    Could you please specify the SPI configuration used in your example, that would help more easily figure out where a problem could be. Please try with the SPI configuration provided within the \Examples\SPI\SPI_FullDuplex_ComDMA example. Please check that you have added the call for the HAL_DMA_IRQHandler() API under the DMA IRQ handler.

    /**
    * @brief This function handles DMA Rx interrupt request. 
    * @param None
    * @retval None 
    */
    void DMA1_Channel4_5_6_7_IRQHandler(void)
    {
    HAL_DMA_IRQHandler(SpiHandle.hdmarx);
    HAL_DMA_IRQHandler(SpiHandle.hdmatx);
    }

    Regards, Heisenberg.