Page 1 of 1

[SOLVED] analogWrite not working on DAC Pins on NUCLEO G071RB

Posted: Mon Jul 27, 2020 6:08 am
by phil_o_matic
I’m running into issues with the DACs on my NUCLEO-G071RB.
According to the STM32Duino API documentation https://github.com/stm32duino/wiki/wiki ... nalogWrite command on Pins PA4 and PA5 (DAC outputs) should result in an analog voltage at the pin driven by the internal DAC.

I tried the Arduino fade example replacing the D13 pin declaration with either PA4 or PA5 but only get a constant 0V at the Pins (LED jumper desoldered).

One possibility would be a missing HAL_DAC_MODULE_ENABLED definition for the STM32G071RB. Is this possible and how do I check this?

Thanks!

Phil

tested code:

Code: Select all

//original source:  http://www.arduino.cc/en/Tutorial/Fade

int OutPin = PA5;         
int brightness = 0;    
int fadeAmount = 5;    


void setup() {
  analogWriteResolution(12);
  pinMode(OutPin, OUTPUT);
}

void loop() {

  analogWrite(OutPin, brightness);
  brightness = brightness + fadeAmount;

  if (brightness <= 0 || brightness >= 4095) {
    fadeAmount = -fadeAmount;
  }
  
  delay(1);
}
tested with and without analogWriteResolution

Re: analogWrite not working on DAC Pins on NUCLEO G071RB

Posted: Mon Jul 27, 2020 7:24 am
by Edogaldo

Re: analogWrite not working on DAC Pins on NUCLEO G071RB

Posted: Mon Jul 27, 2020 9:02 am
by phil_o_matic
Thanks for that hint. I created an buildopt.h and added the -DHAL_DAC_MODULE_ENABLED line.

Sadly I don't get any output from the DAC

Re: [SOLVED] analogWrite not working on DAC Pins on NUCLEO G071RB

Posted: Mon Jul 27, 2020 12:33 pm
by phil_o_matic
Update:
I tried running the DAC with the STM32CubeIDE. The DAC_DataOut Registers had the correct value without any voltage at the output.
Got really frustradet. Had a break and an idea.

The Nucleo I used was used by a colleage before who desoldered the juper for the reference voltage and Vref was therefore at 0V... I thought it was a brand new board and therefore didn't even think about that.

On the other hand it works just fine by now. Thanks for your help!