Loading...
 
Skip to main content

System Workbench for STM32


How To Use DAC on STM32F4 Discovery?

The code generated by the CubeMX will have
HAL_Init();
at the beginning
and also I do not know about "pininit"

Anyway try this example or upload the complete code with cube file
to test it

/*##-1- Initialize the DAC peripheral ######################################*/
if(HAL_DAC_Init(&DacHandle) != HAL_OK)
{
/* Initialization Error */
}

/*##-2- DAC channel2 Configuration #########################################*/
sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

if(HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DACx_CHANNEL1) != HAL_OK)
{
/* Channel configuration Error */
}

/*##-3- DAC channel2 Triangle Wave generation configuration ################*/
if(HAL_DACEx_TriangleWaveGenerate(&DacHandle, DACx_CHANNEL1, DAC_TRIANGLEAMPLITUDE_1023) != HAL_OK)
{
/* Triangle wave generation Error */
}

/*##-4- Enable DAC Channel1 ################################################*/
if(HAL_DAC_Start(&DacHandle, DACx_CHANNEL1) != HAL_OK)
{
/* Start Error */
}

/*##-5- Set DAC channel1 DHR12RD register ################################################*/
if(HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL1, DAC_ALIGN_12B_R, 0x100) != HAL_OK)
{
/* Setting value Error */
}



Best regards
Eng.Mazen

 
Collapse/expand modules below