AnsweredAssumed Answered

STM32F4 DAC not working

Question asked by Zhang.Jizhou on Jan 28, 2017
Latest reply on Jan 30, 2017 by AvaTar

hi,

 

   I am trying to use discovery board DAC module to adjust my external led's brightness by giving different level out voltage.

   I am sure that led is working on 3V, GPIOA.PA5 port also is working.

   But when I run the following my DAC module, the led has no light at all. Any ideas?

 

 

  void main()
  {
    uint32_t Ret;
    HAL_Init();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GPIOInitDef;
    GPIOInitDef.Pin = GPIO_PIN_4;
    GPIOInitDef.Mode = GPIO_MODE_ANALOG;
    GPIOInitDef.Pull = GPIO_NOPULL;
    GPIOInitDef.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIOInitDef);

 

    DAC_HandleTypeDef DACHandleTypeStruct;
    DACHandleTypeStruct.Instance = DAC;
    Ret = HAL_DAC_Init(&DACHandleTypeStruct);

 

    DAC_ChannelConfTypeDef DACChannelConfStruct;
    DACChannelConfStruct.DAC_Trigger = DAC_TRIGGER_NONE;
    DACChannelConfStruct.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
    Ret = HAL_DAC_ConfigChannel(&DACHandleTypeStruct,&DACChannelConfStruct, DAC_CHANNEL_1);
    Ret = HAL_DAC_Start(&DACHandleTypeStruct, DAC_CHANNEL_1);
    HAL_DAC_SetValue(&DACHandleTypeStruct, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 0x0FFF);

 

    while(1)
    {
      ;
    }

}

Outcomes