diff --git a/ProjetsKEIL/Drivers/adcdriver.c b/ProjetsKEIL/Drivers/adcdriver.c index e676215..7a85bed 100644 --- a/ProjetsKEIL/Drivers/adcdriver.c +++ b/ProjetsKEIL/Drivers/adcdriver.c @@ -1 +1,20 @@ #include "adcdriver.h" + +void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr) +{ + RCC->CFGR |= RCC_CFGR_ADCPRE_1; // ADC Prescaler : divided by 6 -> 72MHz to 12MHz + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first + if(ADCStructPtr->channel < 10) + { + ADCStructPtr->ADC->SMPR2 |= (ADCStructPtr->resolution<<(ADCStructPtr->channel*3)); // Cycle and channel selection + } + else { + ADCStructPtr->ADC->SMPR1 |= (ADCStructPtr->resolution<<((ADCStructPtr->channel-10)*3)); // Cycle and channel selection + } + ADCStructPtr->ADC->SQR3 |= ADCStructPtr->channel; //Sequence Reader, seulement le SQ1 est lu dans notre cas, nous associons un channel ŕ ce dernier. + ADCStructPtr->ADC->CR2 |= ADC_CR2_ADON; //ADON Pour l'instant -> PLUS TARD //ADC1->CR2 |= (0x1<<30) //Software start conversion + if(ADCStructPtr->isIT) + { + ADCStructPtr->ADC->CR1 |= ADC_CR1_EOCIE; //Interruption + } +} diff --git a/ProjetsKEIL/Drivers/adcdriver.h b/ProjetsKEIL/Drivers/adcdriver.h index ba3bdcf..4807366 100644 --- a/ProjetsKEIL/Drivers/adcdriver.h +++ b/ProjetsKEIL/Drivers/adcdriver.h @@ -1,10 +1,29 @@ #ifndef ADCDRIVER_H #define ADCDRIVER_H #include "stm32f10x.h" +#include "gpiodriver.h" + +typedef enum{ + cycles1d5 = 0b000, + cycles7d5 = 0b001, + cycles13d5 = 0b010, + cycles28d5 = 0b011, + cycles41d5 = 0b100, + cycles55d5 = 0b101, + cycles71d5 = 0b110, + cycles239d5 = 0b111 +} MyADC_Cycle_t; typedef struct { - GPIO_TypeDef * ADC; //ADC 1 or 2 + ADC_TypeDef * ADC; //ADC 1 or 2 + uint8_t channel; //channel 0 -> 17 + MyADC_Cycle_t resolution; + char isIT; //true -> interrupt driven } MyADC_Struct_TypeDef; +void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr); +MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC); + + #endif diff --git a/ProjetsKEIL/adc/Source/Principale.c b/ProjetsKEIL/adc/Source/Principale.c index b7caf48..25106d0 100644 --- a/ProjetsKEIL/adc/Source/Principale.c +++ b/ProjetsKEIL/adc/Source/Principale.c @@ -1,5 +1,6 @@ #include "stm32f10x.h" #include "../../Drivers/gpiodriver.h" +#include "../../Drivers/adcdriver.h" #define ADCPRE 14 #define SQ1 0 @@ -9,27 +10,14 @@ int main (void) { MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led + MyADC_Struct_TypeDef adcStruct = {ADC1,10,cycles41d5,0}; MyGPIO_Struct_TypeDef adc = {GPIOC,0,In_Analog}; char voltageOverflow = 0; MyGPIO_Init(&led); + MyADC_Init(&adcStruct); MyGPIO_Init(&adc); - RCC->CFGR |= RCC_CFGR_ADCPRE_1;// ADC Prescaler : divided by 6 -> 72MHz to 12MHz - RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first - - - //ADC1->CR1 |= (0x0<<24); //Resolution 12bit -> 00 - //ADC1->CR1 |= (0x1<<5); //Interruption - - //ADC1->CR2 |= (0x1<<30) //Software start conversion - - ADC1->SMPR1 |= (0x4<<0); // ADC0 cycles : 41 - - //ADC_SMPR1 0x4<SQR3 |= (10<CR2 |= (0x1<CR2 |= (0x1<DR >= 3102) diff --git a/ProjetsKEIL/adc/adc.uvoptx b/ProjetsKEIL/adc/adc.uvoptx index 3b06dd0..9b71272 100644 --- a/ProjetsKEIL/adc/adc.uvoptx +++ b/ProjetsKEIL/adc/adc.uvoptx @@ -142,9 +142,9 @@ 0 0 - 34 + 29 1 -
134218954
+
134218844
0 0 0 @@ -153,7 +153,39 @@ 1 .\Source\Principale.c - \\cool_Simule\Source/Principale.c\34 + \\cool_Simule\Source/Principale.c\29 +
+ + 1 + 0 + 23 + 1 +
134218838
+ 0 + 0 + 0 + 0 + 0 + 1 + .\Source\Principale.c + + \\cool_Simule\Source/Principale.c\23 +
+ + 2 + 0 + 22 + 1 +
134218830
+ 0 + 0 + 0 + 0 + 0 + 1 + .\Source\Principale.c + + \\cool_Simule\Source/Principale.c\22
@@ -329,7 +361,7 @@ 0 ST-LINKIII-KEIL_SWO - -U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) + -U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2 0 @@ -433,7 +465,7 @@ 1 1 1 - 1 + 0 0 0 .\Source\Principale.c @@ -456,8 +488,8 @@ 1 0 0 - ..\Drivers\adc.c - adc.c + ..\Drivers\gpiodriver.c + gpiodriver.c 0 0 @@ -465,11 +497,11 @@ 2 3 1 - 1 + 0 0 0 - ..\Drivers\gpiodriver.c - gpiodriver.c + ..\Drivers\timerdriver.c + timerdriver.c 0 0 @@ -480,8 +512,8 @@ 0 0 0 - ..\Drivers\timerdriver.c - timerdriver.c + ..\Drivers\adcdriver.c + adcdriver.c 0 0 diff --git a/ProjetsKEIL/adc/adc.uvprojx b/ProjetsKEIL/adc/adc.uvprojx index 8bd1293..7a718a6 100644 --- a/ProjetsKEIL/adc/adc.uvprojx +++ b/ProjetsKEIL/adc/adc.uvprojx @@ -10,13 +10,14 @@ Simulé 0x4 ARM-ADS - 5060960::V5.06 update 7 (build 960)::.\ARMCC - 0 + 6190000::V6.19::ARMCLANG + 6190000::V6.19::ARMCLANG + 1 STM32F103RB STMicroelectronics - Keil.STM32F1xx_DFP.2.3.0 + Keil.STM32F1xx_DFP.2.4.0 http://www.keil.com/pack/ IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE @@ -186,6 +187,7 @@ 0 0 0 + 0 0 0 8 @@ -313,7 +315,7 @@ 1 - 1 + 2 0 0 1 @@ -322,7 +324,7 @@ 0 0 0 - 2 + 3 0 0 0 @@ -393,11 +395,6 @@ MesDrivers - - adc.c - 1 - ..\Drivers\adc.c - gpiodriver.c 1 @@ -408,6 +405,11 @@ 1 ..\Drivers\timerdriver.c + + adcdriver.c + 1 + ..\Drivers\adcdriver.c + @@ -422,13 +424,14 @@ Réel 0x4 ARM-ADS - 5060960::V5.06 update 7 (build 960)::.\ARMCC - 0 + 6190000::V6.19::ARMCLANG + 6190000::V6.19::ARMCLANG + 1 STM32F103RB STMicroelectronics - Keil.STM32F1xx_DFP.2.3.0 + Keil.STM32F1xx_DFP.2.4.0 http://www.keil.com/pack/ IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE @@ -598,6 +601,7 @@ 0 0 0 + 0 0 0 8 @@ -725,7 +729,7 @@ 1 - 1 + 2 0 0 1 @@ -734,7 +738,7 @@ 0 0 0 - 2 + 3 0 0 0 @@ -805,11 +809,6 @@ MesDrivers - - adc.c - 1 - ..\Drivers\adc.c - gpiodriver.c 1 @@ -820,6 +819,11 @@ 1 ..\Drivers\timerdriver.c + + adcdriver.c + 1 + ..\Drivers\adcdriver.c + @@ -835,15 +839,15 @@ - - + + - + @@ -854,7 +858,7 @@ RTE\Device\STM32F103RB\RTE_Device.h - + @@ -863,7 +867,7 @@ RTE\Device\STM32F103RB\startup_stm32f10x_md.s - + @@ -872,7 +876,7 @@ RTE\Device\STM32F103RB\system_stm32f10x.c - +