1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include "gd32f30x.h"
void rcu_config(void);
/* configure GPIO peripheral */
void gpio_config(void);
/* configure DAC peripheral */
void dac_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* configure RCU peripheral */
rcu_config();
/* configure GPIO peripheral */
gpio_config();
/* configure DAC peripheral */
dac_config();
while(1) {
/* DAC software trigger enable */
dac_concurrent_software_trigger_enable(DAC0);
}
}
void rcu_config(void)
{
/* enable the clock of peripherals */
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_DAC);
}
void gpio_config(void)
{
/* configure PA4 and PA5 as DAC output */
gpio_init(GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_4 | GPIO_PIN_5);
}
void dac_config(void)
{
/* initialize DAC */
dac_deinit(DAC0);
/* DAC trigger config */
dac_trigger_source_config(DAC0, DAC_OUT0, DAC_TRIGGER_SOFTWARE);
dac_trigger_source_config(DAC0, DAC_OUT1, DAC_TRIGGER_SOFTWARE);
/* DAC trigger enable */
dac_trigger_enable(DAC0, DAC_OUT0);
dac_trigger_enable(DAC0, DAC_OUT1);
/* DAC wave mode config */
dac_wave_mode_config(DAC0, DAC_OUT0, DAC_WAVE_MODE_LFSR);
dac_lfsr_noise_config(DAC0, DAC_OUT0, DAC_LFSR_BITS9_0);
dac_wave_mode_config(DAC0, DAC_OUT1, DAC_WAVE_MODE_LFSR);
dac_lfsr_noise_config(DAC0, DAC_OUT1, DAC_LFSR_BITS10_0);
/* DAC enable */
dac_concurrent_enable(DAC0);
dac_concurrent_data_set(DAC0, DAC_ALIGN_12B_R, 0x7F0, 0x7F0);
}
|