cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 DAC PA4/PA5

wardac
Associate
Posted on November 12, 2015 at 20:21

I am generating music using STM32L152RC.

I have DAC configured the same for both channels DAC_OUT1/2 using PA4/PA5.

RCC->APB1ENR |= RCC_APB1ENR_DACEN; 
// Enable DAC
RCC->AHBENR |= RCC_AHBENR_GPIOAEN; 
// enable GPIOA
// PA4/5 Analog
GPIOA->MODER |= 0x00000F00;
// Enable DAC channel1 output buffer
DAC->CR &= ~(DAC_CR_BOFF1 | DAC_CR_BOFF2); 
// Select TIM4 TRGO as trigger
DAC->CR |= (DAC_CR_TEN1 | DAC_CR_TEN2); 
// Enable DAC channel 1 & 2 Trigger 
DAC->CR &= ~(DAC_CR_TSEL1 | DAC_CR_TSEL2); 
DAC->CR |= (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0); 
// 101 = TIM4_TRGO
DAC->CR |= (DAC_CR_TSEL2_2 | DAC_CR_TSEL2_0); 
// 101 = TIM4_TRGO 
// Enable DAC
DAC->CR |= (DAC_CR_EN1 | DAC_CR_EN2); 
// DAC channel 1 & 2 enable

I write to the DAC thus:

static
uint32_t ch2out, ch1out;
............
ch2out = (y << 16);
ch1out = (y);
DAC->DHR12RD = ch2out | ch1out;
............

So here's the problem. When I connect PA5 to my speaker setup (an LM386 opamp), it sounds exactly as expected. But when I disconnect PA5 and connect PA4 to the same exact setup, changing nothing else, the output is inaudible. From the code, you can see that PA4/PA5 , DAC_OUT1/DAC_OUT2 are configured exactly the same, and exactly the same signal is being written to each channel. When I disconnect both PA4/5 from the circuit and used an oscilloscope with my code running, they both show exactly the same output. Yet somehow connecting PA4 to an actual circuit is not working. Also, I tried the program on a second board, and got the same results. I'm not really sure what to make of it. How are PA4 and PA5 different? What am I missing?
3 REPLIES 3
Posted on November 13, 2015 at 06:40

And when the amplifier is connected to PA4, what does the oscilloscope show?

JW

wardac
Associate
Posted on November 13, 2015 at 20:26

The waveform is the same as before.

Posted on November 13, 2015 at 22:55

If the output waveform of one channel is the same as of the other channel, when you connect the amplifier, then you didn't actually connect the amplifier. Follow the wires with the oscilloscope up to the very end, i.e. the speaker; compare wafeforms to the case when connected to the other channel.

JW