/* p7_4.c: Use DAC to generate sawtooth waveform * The DAC is initialized with no buffer or trigger, so every * write to the DAC data register will change the analog output. * The data is incremented in the loop and written to the DAC. * The output of DAC is on pin PA4. * * This program was tested with Keil uVision v5.24a with DFP v2.11.0. */ #include "stm32f4xx.h" int main(void) { int data; RCC->AHB1ENR |= 1; /* enable GPIOA clock */ GPIOA->MODER |= 0x00000300; /* PA4 analog */ /* setup DAC */ RCC->APB1ENR |= 1 << 29; /* enable DAC clock */ DAC->CR |= 1; /* enable DAC */ while(1) { DAC->DHR12R1 = data++ & 0x0FFF; } }