-
Notifications
You must be signed in to change notification settings - Fork 0
/
dac_mobile.c
30 lines (24 loc) · 929 Bytes
/
dac_mobile.c
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
#include "dac_mobile.h"
void InitDACMobile(void) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef PORTA;
GPIO_StructInit(&PORTA);
PORTA.GPIO_Mode = GPIO_Mode_AIN;
PORTA.GPIO_Pin = GPIO_Pin_5;
PORTA.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &PORTA);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
TIM7->PSC = 5;
TIM7->ARR = 600;
TIM_ITConfig(TIM7, TIM_DIER_UIE , ENABLE);
TIM_SelectOutputTrigger(TIM7, TIM_TRGOSource_Update);
TIM_Cmd(TIM7, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
DAC_InitTypeDef DAC_InitStructure;
DAC_StructInit(&DAC_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_2, ENABLE);
}