Why won't DAC channel 2 output higher than 0.5V on STM32L432 ?
Hello,
I'm trying to use both channels of the DAC on STM32L432, but I'm having a very annoying issue: channel 2 only goes up to 0.5V! I think I've configured both channels correctly, because both channels output voltage that changes with my code... but the output just looks like this:
What I expected to see was two identical triangle waves... I'm sweeping an integer from 0-4095 and back down to 0, and sending it to both DAC's. I've tried multiple different commands to write the values to the DAC's, including:
HAL_DAC_SetValue(&hdac1, 1, DAC_ALIGN_12B_R, dac_val);
HAL_DAC_SetValue(&hdac1, 2, DAC_ALIGN_12B_R, dac_val);
and this:
DAC1->DHR12R1 = dac_val;
DAC1->DHR12R2 = dac_val;
and this:
HAL_DACEx_DualSetValue(&hdac1, DAC_ALIGN_12B_R, dac_val, dac_val);
All produce the exact same wave forms in the photo... Am I doing something wrong? Do I need to configure the two channels differently?
Here is my config:
static void MX_DAC1_Init(void)
{
DAC_ChannelConfTypeDef sConfig = {0};
/** DAC Initialization
*/
hdac1.Instance = DAC1;
if (HAL_DAC_Init(&hdac1) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT1 config
*/
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT2 config
*/
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
}
Any information that anyone could give me on this would be greatly appreciated. I could not find any tutorials or examples where people are using BOTH DAC channels.
Thank you!
