2015-12-18 07:40 AM
Hi
i am using stm32f4 discvery. i have configured spi for display nd it works perfectly.Then i have included the DMA, but its not working when i am checking the flag./* checking the below flag */while (DMA_GetFlagStatus(DMA2_Stream5, DMA_FLAG_TCIF5)==RESET);kindly help. The configuration is below,(spi works perfectly without dma).void spi_dmanvic_config(){ //clock for the dma ------ dma2 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); //DMA configuration for spi DMA_InitTypeDef DMA_InitStructure; DMA_InitStructure.DMA_BufferSize = tx_BufferSize; //buffer size DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)(&SPI6->DR); DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_Low; /* Configure TX DMA */ DMA_InitStructure.DMA_Channel = DMA_Channel_1 ; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)(&spi_TxBuffer) ; DMA_Init(DMA2_Stream5, &DMA_InitStructure); DMA_ITConfig(DMA2_Stream5, DMA_IT_TC , ENABLE); //enable the dma DMA_Cmd(DMA2_Stream5, ENABLE); //spi request for transmission SPI_I2S_DMACmd(SPI6, SPI_I2S_DMAReq_Tx, ENABLE); /*** interrupt *****/ NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel =DMA2_Stream5_IRQn ; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = DISPLAY_PRIORITY ; NVIC_InitStruct.NVIC_IRQChannelSubPriority = DISPLAY_SUBPRIORITY ; NVIC_Init(&NVIC_InitStruct);}2015-12-18 08:56 AM
And is the DMA flagging some kind of error instead?
Probably want to configure the NVIC before you enable the interrupt.How is the SPI configured? There's not really enough context here to see exactly what's going on. I would probably separate things out here, the DMA transfer needs to be initialized for each transfer, the clocks, NVIC, and AHB do not.2015-12-18 10:29 AM
clive , i made some changes and the code works.
Without DMA, i am sending a data(8 bit - spi) to the display. and i am doing like the below.void write_data(uint8_t data){ LCD_CONTROL1; // pull to high (A0 line)-- for cmmand or data LCD_CS0; // pul down chip select spi6_sendByte(data); st7783s_delay(LCD_SPI_PAUSE); LCD_CS1; //pull high chipselect to stop transmission.}how can i effecintly send the data when i am using dma ?.. do i need to put the above code in dma handlar ?, if i do that then whats the purpose of dma?... and how it differes from normal spi transmission and spi dma transmission.?2015-12-18 11:02 AM
It will depend a lot on the amount of interaction you need on the CS (Chip Select) pin. The STM32 is very poor in managing that, so it becomes a GPIO task. If the device you are talking too can take a longer stream of data (>4 bytes) while CS is low, then DMA might be usable. The DMA TC handler would need to wait for the SPI to complete and then pull CS high. The DMA TC fires once it send the last byte to the SPI output data buffer, which is going to occur before the last bit hits the wire of the SPI interface.
2015-12-18 11:37 AM
ok, clive..