cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 discovery DMA with SPI

j.Dhananjay
Associate II
Posted on March 02, 2016 at 14:00

Hello everyone, I'm trying to initialize the DMA for SPI2 but DMA is not working for my code , I don't know the reason. Surely I can say that it's not working as the LED which is turned ON in ISR is not glowing. My code for DMA is shown below, please someone help me to understand why it's not working.

//DMA1_Channel5 interrupt service routine
void DMA1_Channel5_IRQHandler(void)
{
GPIOE->BSRR |=1<<
14
;
DMA_ClearITPendingBit(DMA1_IT_GL5);
}
// DMA initialization
void DMA_init(void)
{
DMA_InitTypeDef DMA_InitStructure;
u16 
some_val
=
COLOR_YELLOW
;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
//reset DMA1 channe5 to default values;
DMA_DeInit(DMA1_Channel5);
//channel will not be used for memory to memory transfer
DMA_InitStructure.DMA_M2M
= 
DMA_M2M_Disable
;
//setting normal mode (non circular)
DMA_InitStructure.DMA_Mode
= 
DMA_Mode_Normal
;
//medium priority
DMA_InitStructure.DMA_Priority
= 
DMA_Priority_Medium
;
//source and destination data size 
word
=
16bit
DMA_InitStructure.DMA_PeripheralDataSize
= 
DMA_PeripheralDataSize_HalfWord
;
DMA_InitStructure.DMA_MemoryDataSize
= 
DMA_MemoryDataSize_HalfWord
;
//automatic memory increment disable for both Destination and source
DMA_InitStructure.DMA_MemoryInc
= 
DMA_MemoryInc_Disable
;
DMA_InitStructure.DMA_PeripheralInc
= 
DMA_PeripheralInc_Disable
;
//Location assigned to peripheral register will be destination
DMA_InitStructure.DMA_DIR
= 
DMA_DIR_PeripheralDST
;
//chunk of data to be transfered
DMA_InitStructure.DMA_BufferSize
= 
64000
;
//source and destination start addresses
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI2->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&some_val;
//send values to DMA registers
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
// Enable DMA1 Channe5 Transfer Complete interrupt
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, DISABLE);
//ENABLE DMA1 channel5
DMA_Cmd(DMA1_Channel5, ENABLE);
}

3 REPLIES 3
Posted on March 02, 2016 at 15:10

So perhaps the SPI isn't generating DMA requests?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
j.Dhananjay
Associate II
Posted on March 03, 2016 at 15:24

Yes, Clive1 you are correct SPI is not generating request, it's working now but it's generating interrupt after completion of transmission.

DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, DISABLE);

even after changing the above line to

DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE);

Posted on March 03, 2016 at 16:52

Perhaps the issue is with code you are not showing? As I always recommend posting a complete/concise example that demonstrates the problem.

When doing a selective cut-n-paste it assumes you're looking in the right place, but if you were you'd probably have already solved the issue.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..