cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Slave Tx DMA wont stop

siva
Associate
Posted on September 26, 2016 at 09:12

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 STM 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. #!stm32-!spi-!dma #!tx
1 REPLY 1
slimen
Senior
Posted on September 26, 2016 at 17:46

Hi,

There are SPI examples in the 

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32065.html

libraries, may be this help you.

You will have to make the integration and get inspiration from this example to develop your application:

STM32F4xx_DSP_StdPeriph_Lib_V1.7.1\Project\STM32F4xx_StdPeriph_Examples\SPI\SPI_TwoBoards\SPI_DataExchangeDMA

Regards