1
\$\begingroup\$

I am using stm32f103 to transmit some data over SPI while stm32 acts as slave. I need to use DMA for sending data to the SPI but the corresponding interrupt handler is never called.

The initialization code comes in the following:

DMA_InitTypeDef DMA_InitStructure;
/* DMA configuration */
DMA_DeInit(SPI_SLAVE_DMA);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) SPI_SLAVE_DR_Adress;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) SPI_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = SPI_BufferSize;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(SPI_SLAVE_DMA, &DMA_InitStructure);
/* Enable DMA Transfer Complete interrupt */
DMA_ITConfig(SPI_SLAVE_DMA, DMA_IT_TC, ENABLE);
/* Enable DMA */
DMA_Cmd(SPI_SLAVE_DMA, ENABLE);

/* SPI_SLAVE configuration */
SPI_InitTypeDef SPI_InitStructure;
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI_SLAVE, &SPI_InitStructure);

/* Enable SPI_SLAVE Tx request */
SPI_I2S_DMACmd(SPI_SLAVE, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable SPI_SLAVE */
SPI_Cmd(SPI_SLAVE, ENABLE);

When I use SPI interrupt handler, my system works. But using the code written above, interrupt handler of SPI_SLAVE_DMA channel is never called.

\$\endgroup\$
5
\$\begingroup\$

I found the solution. In reference manual of STM32f103xx there is a table (No. 78) clarifying that which DMA channel can be used for which peripheral. According to that table, I had to use DMA1 channel3, while I was using channel6 instead.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.