AnsweredAssumed Answered

SPI Slave Tx DMA wont stop

Question asked by mohan.sivakumar.001 on Sep 26, 2016
Latest reply on Sep 26, 2016 by ForumSTM32.ForumSTM3
In my application STM32F411 is a SPI slave (TI mode) and the master microcontroller transmits data as packets perpetually till an acknowledgement is received from STM32. After a packet of data is received by STM32, I prepare the ack frame, disable SPI Tx DMA, set the data counter using,

DMA_SetCurrDataCounter() function and enable the dma.

What I observe is,  after the first acknowledgement frame is transmitted, the SPI Tx DMA EN bit gets cleared and the NDTR register reads zero, but the SPI continues to transmit the last byte as long as there is activity on the SPI bus. This happens even when the core is stopped in debug mode and the DMA EN bit is set manually after initialising the DMA registers. Here is the code that I use to initialize the registers.


DMA_StructInit(&SPI_Tx_DMA_Init);
 
SPI_Tx_DMA_Init.DMA_Channel = SPI_TX_DMA_CHANNEL;
SPI_Tx_DMA_Init.DMA_PeripheralBaseAddr = (uint32_t)(&(SPI4->DR));
SPI_Tx_DMA_Init.DMA_Memory0BaseAddr = (uint32_t)dma_tx_buffer;
SPI_Tx_DMA_Init.DMA_DIR = DMA_DIR_MemoryToPeripheral;
SPI_Tx_DMA_Init.DMA_BufferSize = DMA_BUFFER_SIZE;
SPI_Tx_DMA_Init.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
SPI_Tx_DMA_Init.DMA_MemoryInc = DMA_MemoryInc_Enable;
SPI_Tx_DMA_Init.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
SPI_Tx_DMA_Init.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
SPI_Tx_DMA_Init.DMA_Mode = DMA_Mode_Normal;
SPI_Tx_DMA_Init.DMA_Priority = DMA_Priority_Medium;
SPI_Tx_DMA_Init.DMA_FIFOMode = DMA_FIFOMode_Disable;
SPI_Tx_DMA_Init.DMA_MemoryBurst = DMA_MemoryBurst_Single;
SPI_Tx_DMA_Init.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(SPI_TX_DMA_STREAM, &SPI_Tx_DMA_Init);
 
 
/* Enable the DMA SPI TX Stream */
//DMA_Cmd(SPI_TX_DMA_STREAM, ENABLE);

Here is the code that I use to start the SPI Tx DMA transfer.
/* Disable the DMA SPI TX Stream */
DMA_Cmd(SPI_TX_DMA_STREAM, DISABLE);
DMA_SetCurrDataCounter(SPI_TX_DMA_STREAM,size);    
 
/* Enable the DMA SPI TX Stream */
DMA_Cmd(SPI_TX_DMA_STREAM, ENABLE);

Please let me know how to fix this. Thanks.

Outcomes