Closed tomazvidovic closed 1 year ago
if defined(ALX_STM32L4)
me->chdac[buffPos].DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
me->chdac[buffPos].DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE;
me->chdac[buffPos].DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
me->chdac[buffPos].DAC_Trigger = DAC_TRIGGER_NONE;
me->chdac[buffPos].DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_HoldTime = 0;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_RefreshTime = 0;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_SampleTime = 0;
me->chdac[buffPos].DAC_UserTrimming = DAC_TRIMMING_FACTORY;
me->chdac[buffPos].DAC_TrimmingValue = 1;
#endif
DAC_SampleAndHoldConfig is used only when DAC_SampleAndHold is enabled. Everything else is set to default. DAC was tested and it works.
here is good idea to set all structure variables always in the same order as they are specified in declaration:
stm32l4xx_hal_dac.h - Declaration
typedef struct
{
#if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
uint32_t DAC_HighFrequency; /*!< Specifies the frequency interface mode
This parameter can be a value of @ref DAC_HighFrequency */
#endif /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
uint32_t DAC_SampleAndHold; /*!< Specifies whether the DAC mode.
This parameter can be a value of @ref DAC_SampleAndHold */
uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
This parameter can be a value of @ref DAC_trigger_selection */
uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
This parameter can be a value of @ref DAC_output_buffer */
uint32_t DAC_ConnectOnChipPeripheral ; /*!< Specifies whether the DAC output is connected or not to on chip peripheral .
This parameter can be a value of @ref DAC_ConnectOnChipPeripheral */
uint32_t DAC_UserTrimming; /*!< Specifies the trimming mode
This parameter must be a value of @ref DAC_UserTrimming
DAC_UserTrimming is either factory or user trimming */
uint32_t DAC_TrimmingValue; /*!< Specifies the offset trimming value
i.e. when DAC_SampleAndHold is DAC_TRIMMING_USER.
This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
DAC_SampleAndHoldConfTypeDef DAC_SampleAndHoldConfig; /*!< Sample and Hold settings */
} DAC_ChannelConfTypeDef;
I fixed to this:
#if defined(ALX_STM32L4)
me->chdac[buffPos].DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE;
me->chdac[buffPos].DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
me->chdac[buffPos].DAC_Trigger = DAC_TRIGGER_NONE;
me->chdac[buffPos].DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
me->chdac[buffPos].DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
me->chdac[buffPos].DAC_UserTrimming = DAC_TRIMMING_FACTORY;
me->chdac[buffPos].DAC_TrimmingValue = 1;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_SampleTime = 0;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_HoldTime = 0;
me->chdac[buffPos].DAC_SampleAndHoldConfig.DAC_RefreshTime = 0;
#endif
now only two members are set, others are undefined values, this can cause problems...