cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 DAC channel 1 with DMA not working

ihouses ihouses
Associate III

Hello,

I am generating a waveform by using the DAC, channel 1 in circular mode. Timer 7 is ​configured as trigger out even in DAC out1 settings.

When I generate values manually (without the DMA) everything works as expected but if I use the DMA the output is kind of random waveform.

What could be the problem?

Thanks,

The code is:

uint16_t sine_wave_array[32] = {0x80,0x98,0xb0,0xc6,0xda,0xea,0xf5,0xfd,

0xff,0xfd,0xf5,0xea,0xda,0xc6,0xb0,0x98,

0x80,0x67,0x4f,0x39,0x25,0x15,0xa,0x2,

0x0,0x2,0xa,0x15,0x25,0x39,0x4f,0x67};

HAL_TIM_Base_Start(&htim7);

__HAL_TIM_ENABLE(&htim7);

HAL_DAC_Start(&hdac,DAC_CHANNEL_1);

HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*)sine_wave_array, 32, DAC_ALIGN_12B_R);

while(1)

{}

The working code is (in this case I use timer6 to generate a delay):

while(1)

{

  tmp = (uint32_t)hdac.Instance + DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R); 

*(__IO uint32_t *) tmp = sine_wave_array[i++];

if(i>31){i=0;}

TIM6->CNT= 0; while(TIM6->CNT < 100);

}

DAC init is:

hdac.Instance = DAC;

if (HAL_DAC_Init(&hdac) != HAL_OK)

{

Error_Handler();

}

/** DAC channel OUT1 config

*/

sConfig.DAC_Trigger = DAC_TRIGGER_T7_TRGO;

sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)

{

Error_Handler();

}

Timer 7 init is:

static void MX_TIM7_Init(void)

{

/* USER CODE BEGIN TIM7_Init 0 */

/* USER CODE END TIM7_Init 0 */

TIM_MasterConfigTypeDef sMasterConfig = {0};

/* USER CODE BEGIN TIM7_Init 1 */

/* USER CODE END TIM7_Init 1 */

htim7.Instance = TIM7;

htim7.Init.Prescaler = 0;

htim7.Init.CounterMode = TIM_COUNTERMODE_UP;

htim7.Init.Period = 32768;

htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim7) != HAL_OK)

{

Error_Handler();

}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN TIM7_Init 2 */

/* USER CODE END TIM7_Init 2 */

}

1 REPLY 1

Read out and check/post the respective DAC and DMA registers' content.

JW