cancel
Showing results for 
Search instead for 
Did you mean: 

Spi with dma

arunease
Associate II
Posted on January 07, 2016 at 16:05

the goal is to tranfer the data from memory to spi. The buffer values are 32 bit. and the spi data register is 16 bit. i made a configuration to take the 32 bit value and put it in fifo, then take 16 bit value from fifo and put it in spi data register.

the dma did not work. is there any problem with the configuration.. please help me 

The configuration is below. 

#define buffer_count 1200

uint32_t buffer[buffer_count]; 

void spi_dma2d_halfword(SPI_TypeDef* SPIx)

{

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc =  DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

DMA_InitStructure.DMA_Priority = DMA_Priority_Low;

DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable ; 

DMA_InitStructure.DMA_FIFOThreshold =  DMA_FIFOThreshold_1QuarterFull;

DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4 ;  //1 burst fo 4 beats

DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

** memory data size   */

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryInc =  DMA_MemoryInc_Enable;

 /* Configure TX DMA */

DMA_InitStructure.DMA_BufferSize = buffer_count ;       //buffer size

DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)(&SPI6->DR);

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)(&outpuf_pfc) ;

/**** channel and direction ***/

DMA_InitStructure.DMA_Channel = DMA_Channel_1 ;

DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ;

/*** initialize ***/

DMA_Init(DMA2_Stream5, &DMA_InitStructure);

}
4 REPLIES 4
Posted on January 07, 2016 at 19:17

The buffer values are 32 bit. and the spi data register is 16 bit. 

I don't think the SPI/DMA care what form the data is for the C compiler, it's just words in memory. I'd probably lean to doing 16-bit memory accesses, double the transfer count, and let it pull the 32-bit data as a pair of 16-bit half-words.

the dma did not work.

What does that mean? Transferred the wrong data, threw and error?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock
Associate III
Posted on January 07, 2016 at 19:36

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)(&outpuf_pfc) ;

Where is output_pfc defined?  Is it word aligned and the same size as buffer_count?

arunease
Associate II
Posted on January 08, 2016 at 12:22

clive, i can do how you suggested. 

what you mean by I don't think the SPI/DMA care what form the data is for the C compiler, it's just words in memory. 

jpeacock
Associate III
Posted on January 08, 2016 at 13:42

Packing and unpacking (converting 32 bit memory to two 16-bit SPI outputs) is performed in the DMA hardware using the DMA FIFO buffer.  AS long as memory is aligned to the declared boundary (32 bit in this case) it won't matter what compiler you are using, memory location is the same.