From d015a139e1741b51867640c938172f4ecdbf56f4 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 22 Mar 2023 16:47:22 +0100 Subject: [PATCH] Added basic ADC --- ProjetsKEIL/adc/RTE/_R_el/RTE_Components.h | 2 +- ProjetsKEIL/adc/Source/Principale.c | 43 +++++- ProjetsKEIL/adc/adc.uvoptx | 155 ++++++--------------- ProjetsKEIL/adc/adc.uvprojx | 20 +++ 4 files changed, 102 insertions(+), 118 deletions(-) diff --git a/ProjetsKEIL/adc/RTE/_R_el/RTE_Components.h b/ProjetsKEIL/adc/RTE/_R_el/RTE_Components.h index 849a0e6..1e5a4b5 100644 --- a/ProjetsKEIL/adc/RTE/_R_el/RTE_Components.h +++ b/ProjetsKEIL/adc/RTE/_R_el/RTE_Components.h @@ -3,7 +3,7 @@ * Auto generated Run-Time-Environment Configuration File * *** Do not modify ! *** * - * Project: 'gpiodriver' + * Project: 'adc' * Target: 'Réel' */ diff --git a/ProjetsKEIL/adc/Source/Principale.c b/ProjetsKEIL/adc/Source/Principale.c index 8f04e3d..10fb923 100644 --- a/ProjetsKEIL/adc/Source/Principale.c +++ b/ProjetsKEIL/adc/Source/Principale.c @@ -1,6 +1,47 @@ #include "stm32f10x.h" +#include "../../Drivers/gpiodriver.h" + +#define ADCPRE 14 +#define SQ1 0 + +#define ADON 0 int main (void) { - while(1){}; + MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led + MyGPIO_Struct_TypeDef adc = {GPIOC,0,In_Analog}; + char voltageOverflow = 0; + + MyGPIO_Init(&led); + MyGPIO_Init(&adc); + + RCC->CFGR |= (0x2< 72MHz to 12MHz + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; + + + //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) + { + MyGPIO_Set(GPIOA,5); + voltageOverflow = 1; + } + else{ + if(!voltageOverflow) + { + MyGPIO_Reset(GPIOA,5); + } + } + }; } diff --git a/ProjetsKEIL/adc/adc.uvoptx b/ProjetsKEIL/adc/adc.uvoptx index 2cd4f75..3b06dd0 100644 --- a/ProjetsKEIL/adc/adc.uvoptx +++ b/ProjetsKEIL/adc/adc.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -125,7 +125,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1468,53,1889,480,1)(121=1469,437,1890,864,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1285,87,1879,838,1)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1468,53,1889,480,1)(121=1469,437,1890,864,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=10,543,409,888,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=723,147,1317,898,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=869,137,1472,888,1)(151=-1,-1,-1,-1,0) 0 @@ -142,9 +142,9 @@ 0 0 - 15 + 34 1 -
134218740
+
134218954
0 0 0 @@ -153,87 +153,7 @@ 1 .\Source\Principale.c - \\cool_Simule\Source/Principale.c\15 -
- - 1 - 0 - 19 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - -
- - 2 - 0 - 7 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - -
- - 3 - 0 - 8 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - -
- - 4 - 0 - 5 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - -
- - 5 - 0 - 6 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - + \\cool_Simule\Source/Principale.c\34
@@ -290,16 +210,6 @@ - - - System Viewer\GPIOA - 35905 - - - System Viewer\GPIOB - 35904 - - 1 1 @@ -364,7 +274,7 @@ 1 0 - 0 + 1 18 @@ -442,24 +352,7 @@ UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))
- - - 0 - 0 - 6 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Source\Principale.c - - -
-
+ 0 @@ -514,6 +407,12 @@ + + + System Viewer\ADC1 + 35905 + + 1 0 @@ -534,7 +433,7 @@ 1 1 1 - 0 + 1 0 0 .\Source\Principale.c @@ -554,7 +453,7 @@ 2 2 1 - 0 + 1 0 0 ..\Drivers\adc.c @@ -562,6 +461,30 @@ 0 0 + + 2 + 3 + 1 + 1 + 0 + 0 + ..\Drivers\gpiodriver.c + gpiodriver.c + 0 + 0 + + + 2 + 4 + 1 + 0 + 0 + 0 + ..\Drivers\timerdriver.c + timerdriver.c + 0 + 0 + diff --git a/ProjetsKEIL/adc/adc.uvprojx b/ProjetsKEIL/adc/adc.uvprojx index ef99b19..8bd1293 100644 --- a/ProjetsKEIL/adc/adc.uvprojx +++ b/ProjetsKEIL/adc/adc.uvprojx @@ -398,6 +398,16 @@ 1 ..\Drivers\adc.c + + gpiodriver.c + 1 + ..\Drivers\gpiodriver.c + + + timerdriver.c + 1 + ..\Drivers\timerdriver.c + @@ -800,6 +810,16 @@ 1 ..\Drivers\adc.c + + gpiodriver.c + 1 + ..\Drivers\gpiodriver.c + + + timerdriver.c + 1 + ..\Drivers\timerdriver.c +