cancel
Showing results for 
Search instead for 
Did you mean: 

Question about looping a DMA transfer to the internal DAC

Andrew C
Associate II

I have a question with regards to DMA. When I do transfer, do I have to re-transfer once I finished transferring my data to the DAC? I am trying to just have go through the same points over and over again, so it could be a time saver if i could do this. Or do I have to steam the data each time i want to start again?

5 REPLIES 5

If the data are in RAM and you don''t overwrite them, you can reuse them, they don't wear out.

JW

In Circular Mode the DMA will transfer the same buffer memory to the DAC over and over, endlessly.

One typically does this while enabling the DMA HT and TC interrupts triggering at the half way point and completion, allowing for the buffer to be updated from a file, or reconstructed via a formula generating multiple frequencies, amplitudes, etc. Often referred to as ping-pong buffering, it permits you to update the inactive half of the buffer while the other half transfers.

Typically not doing a handful of bytes at a time, or reinitailizing DMA repetitively.

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

Thanks....So I tried doing DMA, but it outputs a random pulse and then nothing happens. I think the values I am feeding it do nothing because the waveform looks the same no matter what. You guys mind taking a look at my code to see what i am doing wrong? I am just stuck now :( I put the 2 ways I generated array data...and they both show the same random waveform.

  /*uint16_t array[40];
  uint8_t i = 0;
  uint32_t sampleSize;
 
 
  while (i<40)
  {
	  array[i] = i*100;
	  i++;
  }
 
 
  sampleSize = (sizeof (array) / sizeof (array[0]));*/
 
 
  const uint16_t sine_wave_array[32] = {2047, 1648, 1264, 910, 600,  345,
                     156, 39,  0,  39,  156,  345,
                     600, 910, 1264, 1648, 2048, 2447,
                     2831, 3185, 3495, 3750, 3939, 4056,
                     4095, 4056, 3939, 3750, 3495, 3185,
                     2831, 2447};
 
 
  LL_TIM_EnableCounter(TIM6); //start timer 6
 
  LL_DAC_Enable(DAC, LL_DAC_CHANNEL_1); //enable DAC
 
  LL_DAC_EnableTrigger(DAC, LL_DAC_CHANNEL_1); //enable Trigger for DAC
 
 
  LL_DMA_EnableIT_TE(DMA1,LL_DMA_STREAM_5);
 
  //LL_DMA_ConfigAddresses(DMA1,
  //                         LL_DMA_STREAM_5,
  //                         (uint32_t)&array,
  //                         LL_DAC_DMA_GetRegAddr(DAC1, LL_DAC_CHANNEL_1, LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED),
  //                         LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
 
  LL_DMA_ConfigAddresses(DMA1,
                           LL_DMA_STREAM_5,
                           (uint32_t)&sine_wave_array,
                           LL_DAC_DMA_GetRegAddr(DAC1, LL_DAC_CHANNEL_1, LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED),
                           LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
 
 
  uint32_t sampleSize = (sizeof (sine_wave_array) / sizeof (sine_wave_array[0]));
 
  LL_DMA_SetDataLength(DMA1,
                        LL_DMA_STREAM_5,
                        sampleSize);
 
 
  LL_DMA_EnableStream(DMA1,LL_DMA_STREAM_5);

Andrew C
Associate II

OK, I got...turns out I was missing lots of code enabling more DAC to DMA things.

Thanks!

STM32Cube_FW_F4_V1.21.0\Projects\STM32F429ZI-Nucleo\Examples_LL\DAC\DAC_GenerateWaveform_TriggerHW\Src\main.c

  /*## Configuration of DMA ##################################################*/
 
  /* Enable the peripheral clock of DMA */
  LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
  /* Configure the DMA transfer */
  /*  - DMA transfer in circular mode to have an unlimited DAC signal         */
  /*    generation.                                                           */
  /*  - DMA transfer to DAC without address increment.                        */
  /*  - DMA transfer from memory with address increment.                      */
  /*  - DMA transfer to DAC by half-word to match with DAC resolution 12 bits */
  /*  - DMA transfer from memory by half-word to match with DAC data          */
  /*    buffer variable type: half-word.
                                      */
 
  LL_DMA_SetChannelSelection(DMA1, LL_DMA_STREAM_5, LL_DMA_CHANNEL_7);
  LL_DMA_ConfigTransfer(DMA1,
                        LL_DMA_STREAM_5,
                        LL_DMA_DIRECTION_MEMORY_TO_PERIPH |
                        LL_DMA_MODE_CIRCULAR              |
                        LL_DMA_PERIPH_NOINCREMENT         |
                        LL_DMA_MEMORY_INCREMENT           |
                        LL_DMA_PDATAALIGN_HALFWORD        |
                        LL_DMA_MDATAALIGN_HALFWORD        |
                        LL_DMA_PRIORITY_HIGH               );
 
 
  /* Set DMA transfer addresses of source and destination */
  LL_DMA_ConfigAddresses(DMA1,
                         LL_DMA_STREAM_5,
                         (uint32_t)&WaveformSine_12bits_32samples,
                         LL_DAC_DMA_GetRegAddr(DAC1, LL_DAC_CHANNEL_1, LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED),
                         LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
 
  /* Set DMA transfer size */
  LL_DMA_SetDataLength(DMA1,
                       LL_DMA_STREAM_5,
                       WAVEFORM_SAMPLES_SIZE);
 
  /* Note: In this example, the only DMA interruption activated is            */
  /*       tranfer error.                                                     */
  /*       If needed, DMA interruptions of half of transfer                   */
  /*       and transfer complete can be activated.                            */
  /*       Refer to DMA examples.                                             */
 
  /*## Activation of DMA #####################################################*/
  /* Enable the DMA transfer */
  LL_DMA_EnableStream(DMA1,
                       LL_DMA_STREAM_5);

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