AnsweredAssumed Answered

Wave generation not working

Question asked by Ecochard.Florent.001 on Jun 24, 2015
I've been trying to use my Nucleo F334's DAC wave generation function to output white noise and I can't get it to work (I'm using Mbed compiler tools)... I used the HAL functions described here, page 218.

Here's the code that I tried : 
01.#include "mbed.h"
03.DAC_HandleTypeDef DAC_InitStructure;
04. main() {
06.    SystemInit();
07.    DAC_InitStructure.Instance = DAC1;
08.    __DAC1_CLK_ENABLE();
09.    HAL_DAC_Init(&DAC_InitStructure);
10.    HAL_DAC_Start(&DAC_InitStructure, DAC_CHANNEL_1);
11.    HAL_DACEx_NoiseWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_LFSRUNMASK_BITS6_0);
12.    while(1);

It compiles correctly but I don't get any output (I'm looking at PA_4 aka A2).
I also tried with HAL_DACEx_TriangleWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_TRIANGLEAMPLITUDE_1023);  but it doesn't work either...
I tried putting the function into the loop : no positive result.
I checked if the STM32F334R8 has the noise generation capacities and it does have it, according to the datasheet...

I'd be glad to have some help!

Thanks friends

EDIT : I just read in the HAL reference that I should enable software trigger before using wave genereation so I did that but still not working

EDIT2 : I tried with TIM6 trigger instead of software trigg with no result. Here is the new code : 
01.#include "mbed.h"
03.DAC_HandleTypeDef DAC_InitStructure;
04.DAC_ChannelConfTypeDef chan1;
05. main() {
07.    SystemInit();
08.    // enable TIM3 peripheral
09.    __TIM6_CLK_ENABLE();
10.    TIM6->CR2 &= 0; // UG used as trigger output
11.    TIM6->PSC = 0; // no prescaler
12.    TIM6->ARR = 72000; // Reload value
13.    TIM6->EGR = TIM_EGR_UG; // Reinitialise the counter
14.    TIM6->DIER = TIM_DIER_UIE; // enable update interrupt
15.    //DAC_InitStructure.Instance = DAC1;
16.    chan1.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
17.    HAL_DAC_ConfigChannel(&DAC_InitStructure, &chan1, DAC_CHANNEL_1);
18.    HAL_DACEx_NoiseWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_LFSRUNMASK_BITS11_0);
19.    HAL_DAC_Init(&DAC_InitStructure);
20.    HAL_DAC_Start(&DAC_InitStructure, DAC_CHANNEL_1);
21.    TIM6->CR1 |= TIM_CR1_CEN;
22.    while(1){
23.        if(TIM3->SR & TIM_SR_UIF) // if UIF flag is set    
24.            TIM3->SR &= ~TIM_SR_UIF; // clear UIF flag  /////   Not really sure about this part, I figured the flag had to be reset somwhere but as i don't have interrupt routine, I didn't know where to do it.
25.    }