Associate II
September 28, 2022
Solved
DUAL MODE DAC OF STM32 F0
- September 28, 2022
- 1 reply
- 1350 views
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();
}
}