cancel
Showing results for 
Search instead for 
Did you mean: 

DMA - from SPI to DAC - 16 bit

JR2963
Senior II

Hi,

I use DMA for transfer data from external flash memory to DAC for playing sounds - in 8 bits mode like that:

1) TIM6  gives impulses to DMA_1 - which transmit  dummy byte to external flash in 8 khz intervals (Fsampling of sound). External flash always response with new sample of sound.

2) Second DMA_2 transfers rx bytes from external mem to DAC (from SPI->DR to DAC->DHR12R1).

All works well, but now I would like to transfer not 8 bits, but 16 (12) bits sounds to DAC.

Is it even possible? MAybe the second DMA had to be set like LL_DMA_PDATAALIGN_BYTE (SPI->DR) from source and LL_DMA_PDATAALIGN_HAL_WORD for destiantion (DAC-DHR12R1)?

2 REPLIES 2

> MAybe the second DMA had to be set like LL_DMA_PDATAALIGN_BYTE (SPI->DR) from source and LL_DMA_PDATAALIGN_HAL_WORD for destiantion (DAC-DHR12R1)?

The names of constants are probably wrong, but that would not work anyway, as the single-port DMA in 'G0 does not assemble/disassemble data, but zero-extends them:

waclawekjan_0-1687943655700.png

You have two options:

- use 16-bit SPI; for that you'd probably need to switch SPI between 8-bit (for commands to memory) and 16-bit mode, or switch memory-facing pins between GPIO and SPI and bit-bang the command

- use memory as a buffer and a third DMA, storing 8-bit data using the second DMA into memory and picking them from memory using the third DMA and storing into DAC. Timing of the third DMA may be tricky, maybe DMAMUX's facilities could be used for that, I am not familiar with DMAMUX.

JW

Sounds good, the second DMA which now transfers from SPI->DR to DAC, just only redirect to memory e.g. uint16_t tempMem, and after this transfer is done, so some event could tell DMA_3 to transfer from tempMEM to DAC...