cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F DAC not driving voltage to more than 0V

gives
Associate

Hello,

I am using a STM32F429I-Discovery board for a project involving the use of both DAC channels. I am using the Peripheral driver library for faster coding. Despite having configured everything as specified in the docs and the library I cannot get the DAC to work. When using PA5, for instance, it remains still at 0V.

int main(void)
{
  GPIO_Config(); // configure all the pins used for this module
  DAC_Configuration();
 
  while(1) {
	  DAC_SetChannel2Data(DAC_Align_12b_R, (uint32_t)868);
  }
}
 
void GPIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;
 
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
 
  // Output CCP signal
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  // PB6 is used as an alternate function. It is used to output a PWM generated by Timer 4
  // This pin generates the output SCP signal.
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4);
 
  // Output PMS signal
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStruct);
 
  // Input CP signal
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  // Input PMS signal
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  // Output Inj
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  // DAC outputs to simulate analog signals
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
}
 
// Phase 2
void DAC_Configuration(void) {
  DAC_InitTypeDef DAC_InitStructure;
 
  /* Enable DAC clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
 
  /* Configure DAC channel 1, 2 */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_2, &DAC_InitStructure);
 
  /* Enable DAC channel 1, 2 */
  DAC_Cmd(DAC_Channel_2, ENABLE);
}

I have omitted most of the code, such as Timer configuration, NVIC, etc. It is not related to the DAC so it should not be affecting it. The debugger shows that all the lines of the code are being reached. I have tried disabling the output buffer as well, without success. The oscillator has been configured, as well as AHB1, APB1 and APB2 clocks. Is there something I am missing? I am measuring the output in PA5 with an oscilloscope (Picoscope 2000 series).

3 REPLIES 3

Check the board's manual and schematics if there is anything on board connected to this pin.

JW

I suspected this might be happening. If I am not mistaken, PA4 is connected to the VSYNC of the display. However, I could not find anything for PA5 so it should be working for the example I provided. If I wanted to use PA4, is there some "virtual" way to disconnect the pin from VSYNC? I guess it's not possible since it is designed and connected like this.

Indeed, PA5 is free to use.

Here is a simple example I've just concocted, to output triangle wave from DAC (using the built-in triangle generator) onto PA5.

JW