1 | #include "stm32f4xx.h"
|
2 | #include "stm32f4xx_conf.h"
|
3 |
|
4 | GPIO_InitTypeDef GPIO_InitStructure;
|
5 | ADC_InitTypeDef ADC_InitStructure;
|
6 | ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
7 | NVIC_InitTypeDef NVIC_adc;
|
8 |
|
9 | uint16_t x;
|
10 | uint16_t y;
|
11 |
|
12 | void Delay(__IO uint32_t nCount) {
|
13 | while(nCount--) {
|
14 | }
|
15 | }
|
16 |
|
17 |
|
18 | void ADC_IRQHandler()
|
19 | {
|
20 | x= ADC_GetConversionValue(ADC1);
|
21 | GPIO_ToggleBits (GPIOD, GPIO_Pin_14|GPIO_Pin_13|GPIO_Pin_12);
|
22 | ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);
|
23 | }
|
24 |
|
25 |
|
26 | int main(void) {
|
27 | /* GPIOD Periph clock enable */
|
28 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
29 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
30 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
31 |
|
32 | /* Configure PD12, 13, 14 and PD15 in output pushpull mode */
|
33 | /* Nur zur Darstellung*/
|
34 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
35 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
36 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
37 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
38 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
39 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
40 |
|
41 | // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
42 | //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
43 | // GPIO_Init(GPIOA,&GPIO_InitStructure);
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
|
50 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
51 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
52 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
53 |
|
54 |
|
55 | ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
|
56 | ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
|
57 | ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
|
58 | ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
59 | ADC_CommonInit(&ADC_CommonInitStructure);
|
60 |
|
61 |
|
62 | ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
|
63 | ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
64 | ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
65 | ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
|
66 | ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1 ;
|
67 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
68 | ADC_InitStructure.ADC_NbrOfConversion = 1;
|
69 | ADC_Init(ADC1, &ADC_InitStructure);
|
70 | ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
|
71 |
|
72 | ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_144Cycles);
|
73 | //ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
|
74 | ADC_Cmd(ADC1, ENABLE);
|
75 | ADC_SoftwareStartConv(ADC1);
|
76 |
|
77 |
|
78 | NVIC_adc.NVIC_IRQChannel = ADC_IRQn;
|
79 | NVIC_adc.NVIC_IRQChannelCmd = ENABLE;
|
80 | NVIC_adc.NVIC_IRQChannelPreemptionPriority = 0x0F;
|
81 | NVIC_adc.NVIC_IRQChannelSubPriority = 0x01;
|
82 | NVIC_Init(&NVIC_adc);
|
83 |
|
84 |
|
85 | while (1)
|
86 | {
|
87 |
|
88 | }
|
89 | }
|