cancel
Showing results for 
Search instead for 
Did you mean: 

DUAL MODE DAC OF STM32 F0

Stark
Associate II

I want to create 2 analog output (DAC) on PA4 & PA5 pin. How to make DAC dual mode as instructed in refmanual? When I use template code and add 1 more DAC channel but no success.please help me how to make 2 DACs simultaneously.

Thanks

static void DAC_Ch1_EscalatorConfig(void)    // DAC channel 1
{
  /*##-1- Initialize the DAC peripheral ######################################*/
  if (HAL_DAC_Init(&DacHandle) != HAL_OK)
  {
    /* Initiliazation Error */
    Error_Handler();
  }
 
  /*##-1- DAC channel1 Configuration #########################################*/
  sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
 
  if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DACx_CHANNEL) != HAL_OK)
  {
    /* Channel configuration Error */
    Error_Handler();
  }
    
 
  /*##-2- Enable DAC Channel1 and associeted DMA #############################*/
    //sine_val
    //if (HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL, (uint32_t *)aEscalator8bit, 6, DAC_ALIGN_8B_R) != HAL_OK)
  if (HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL, (uint32_t *)Wave_LUT8_36, 4608, DAC_ALIGN_8B_R) != HAL_OK)
  {
    /* Start DMA Error */
    Error_Handler();
  }
}
static void DAC_Ch2_EscalatorConfig(void)       //dac channel 2
{
  /*##-1- Initialize the DAC peripheral ######################################*/
  if (HAL_DAC_Init(&DacHandle) != HAL_OK)
  {
    /* Initiliazation Error */
    Error_Handler();
  }
 
  /*##-1- DAC channel1 Configuration #########################################*/
  sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
 
  if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  {
    /* Channel configuration Error */
    Error_Handler();
  }
    
 
  /*##-2- Enable DAC Channel1 and associeted DMA #############################*/
    //sine_val
    //if (HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL, (uint32_t *)aEscalator8bit, 6, DAC_ALIGN_8B_R) != HAL_OK)
  if (HAL_DAC_Start_DMA(&DacHandle, DAC_CHANNEL_2, (uint32_t *)Wave_LUT8_36, 4608, DAC_ALIGN_8B_R) != HAL_OK)
  {
    /* Start DMA Error */
    Error_Handler();
  }
}

0693W00000UFH4yQAH.png

1 ACCEPTED SOLUTION

Accepted Solutions
RomainR.
ST Employee

Hello @danh.1 (Community Member)

I have inspected your code stm32f0xx_hal_msp.c and in the function HAL_DAC_MspInit():

I notice that all the code of the PA5 configuration and which corresponds to the DAC Channel 2 is commented on lines 72 to 75 ? PA5 is not well configured for DAC output.

This is also the case for your DMA, you have configured a single channel DMA1_CHANNEL3 for DAC Channel 1 (PA4) and that is linked to hdma_dac1.

You also need a second DMA1_CHANNEL4 for DAC Channel 2 (PA5) for an hdma_dac2 which you should declare and initialize.

Thank you to tag my answer as best.

Best regards,

Romain,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
RomainR.
ST Employee

Hello @danh.1 (Community Member)

I have inspected your code stm32f0xx_hal_msp.c and in the function HAL_DAC_MspInit():

I notice that all the code of the PA5 configuration and which corresponds to the DAC Channel 2 is commented on lines 72 to 75 ? PA5 is not well configured for DAC output.

This is also the case for your DMA, you have configured a single channel DMA1_CHANNEL3 for DAC Channel 1 (PA4) and that is linked to hdma_dac1.

You also need a second DMA1_CHANNEL4 for DAC Channel 2 (PA5) for an hdma_dac2 which you should declare and initialize.

Thank you to tag my answer as best.

Best regards,

Romain,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.