From 1874f666d4a24ab17ee00c6686e5872242d5f72c Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 7 Apr 2023 15:28:30 +0200 Subject: [PATCH] Added battery and initBattery functions, using external variable uartCool --- driver/adc.c | 6 ++-- driver/adc.h | 2 +- implementation/accelerometer.c | 4 +-- implementation/accelerometer.h | 4 +-- implementation/battery.c | 26 +++++++++++++++ implementation/battery.h | 8 +++++ implementation/remote.c | 1 - keilproject/Source/Principale.c | 3 ++ keilproject/voilier.uvoptx | 56 +++++++++++++++++++++++++++++++-- keilproject/voilier.uvprojx | 20 ++++++++++++ 10 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 implementation/battery.c create mode 100644 implementation/battery.h diff --git a/driver/adc.c b/driver/adc.c index 0ddd5df..4110fa0 100644 --- a/driver/adc.c +++ b/driver/adc.c @@ -1,8 +1,8 @@ #include "adc.h" -void (* pFncADC) (void); /* d�claration d�un pointeur de fonction */ +void (* pFncADC) (uint32_t); /* d�claration d�un pointeur de fonction */ -void MyADC_Init_Periph (void (* ptrFonction)(void)) +void MyADC_Init_Periph (void (* ptrFonction)(uint32_t)) { pFncADC = ptrFonction; /* affectation du pointeur */ } @@ -38,7 +38,7 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio) void ADC1_2_IRQHandler(void) { if (pFncADC != 0) - (*pFncADC) (); /* appel indirect de la fonction */ + (*pFncADC) (ADC1->DR); /* appel indirect de la fonction */ MyADC_Base_Start(ADC1); ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant �tre effectu�e. } diff --git a/driver/adc.h b/driver/adc.h index 849c0d7..caf77b6 100644 --- a/driver/adc.h +++ b/driver/adc.h @@ -23,7 +23,7 @@ typedef struct void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr); void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio); -void MyADC_Init_Periph (void (* ptrFonction)(void)); +void MyADC_Init_Periph (void (* ptrFonction)(uint32_t)); MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC); #define MyADC_Base_Start(ADC) (ADC->CR2 |= ADC_CR2_SWSTART) diff --git a/implementation/accelerometer.c b/implementation/accelerometer.c index 0bb3f14..a70849e 100644 --- a/implementation/accelerometer.c +++ b/implementation/accelerometer.c @@ -3,7 +3,7 @@ #include "MySPI.h" #include "gpio.h" -void accelerometre() +void accelerometre(void) { int dataX ; float GX ; @@ -54,4 +54,4 @@ void accelerometre() -} \ No newline at end of file +} diff --git a/implementation/accelerometer.h b/implementation/accelerometer.h index 1d8a585..e48952b 100644 --- a/implementation/accelerometer.h +++ b/implementation/accelerometer.h @@ -2,7 +2,7 @@ #define INC_ACCELEROMETER_H_ #include "../driver/MySPI.h" -void accelerometre(); +void accelerometre(void); -#endif \ No newline at end of file +#endif diff --git a/implementation/battery.c b/implementation/battery.c new file mode 100644 index 0000000..1e6a9b8 --- /dev/null +++ b/implementation/battery.c @@ -0,0 +1,26 @@ +#include "battery.h" +#include "adc.h" +#include "remote.h" + +extern MyUART_Struct_Typedef uartCool; + +void battery(uint32_t data) +{ + if(data >= 0x420) //0x429 -> approx. 12V + { + MyUART_Send(&uartCool,'h'); + } + else { + MyUART_Send(&uartCool,'l'); + } + +} + +void initBattery(void) +{ + MyADC_Init_Periph(battery); + MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5}; + MyADC_Init(&adcBattery); + MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};; + MyGPIO_Init(&gpioBattery); +} diff --git a/implementation/battery.h b/implementation/battery.h new file mode 100644 index 0000000..343b80b --- /dev/null +++ b/implementation/battery.h @@ -0,0 +1,8 @@ +#ifndef BATTERY_H +#define BATTERY_H +#include "stm32f10x.h" + +void battery(uint32_t data); +void initBattery(void); + +#endif diff --git a/implementation/remote.c b/implementation/remote.c index 5d16ae1..57317d6 100644 --- a/implementation/remote.c +++ b/implementation/remote.c @@ -6,7 +6,6 @@ MyUART_Struct_Typedef uartCool = {USART1,9600,lengthBit8,parityNone,stopBit1}; void remote(uint8_t data) { - MyUART_Send(&uartCool,data); int8_t signedData = (int8_t)data; if(signedData >= 0) { diff --git a/keilproject/Source/Principale.c b/keilproject/Source/Principale.c index 545b510..d4439c1 100644 --- a/keilproject/Source/Principale.c +++ b/keilproject/Source/Principale.c @@ -4,6 +4,8 @@ #include "motoreducteur.h" #include "rtc.h" #include "remote.h" +#include "battery.h" +#include "accelerometer.h" void initImplementation(void); @@ -27,4 +29,5 @@ void initImplementation(void) MyMotor_ChangeDirection(HORAIRE); MyRTC_Init(); accelerometre(); + initBattery(); } diff --git a/keilproject/voilier.uvoptx b/keilproject/voilier.uvoptx index 1daa6dd..9dc48d8 100644 --- a/keilproject/voilier.uvoptx +++ b/keilproject/voilier.uvoptx @@ -272,6 +272,26 @@ STLink\ST-LINKIII-KEIL_SWO.dll + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + (105=-1,-1,-1,-1,0) + 0 ST-LINKIII-KEIL_SWO @@ -290,12 +310,12 @@ 0 0 - 0 + 1 0 0 0 0 - 0 + 1 0 0 0 @@ -326,6 +346,12 @@ + + + System Viewer\ADC1 + 35905 + + 1 0 @@ -414,7 +440,7 @@ 2 6 1 - 0 + 1 0 0 ..\driver\adc.c @@ -478,6 +504,30 @@ 0 0 + + 3 + 11 + 1 + 0 + 0 + 0 + ..\implementation\battery.c + battery.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\implementation\accelerometer.c + accelerometer.c + 0 + 0 + diff --git a/keilproject/voilier.uvprojx b/keilproject/voilier.uvprojx index c74b758..7e45548 100644 --- a/keilproject/voilier.uvprojx +++ b/keilproject/voilier.uvprojx @@ -443,6 +443,16 @@ 1 ..\implementation\remote.c + + battery.c + 1 + ..\implementation\battery.c + + + accelerometer.c + 1 + ..\implementation\accelerometer.c + @@ -890,6 +900,16 @@ 1 ..\implementation\remote.c + + battery.c + 1 + ..\implementation\battery.c + + + accelerometer.c + 1 + ..\implementation\accelerometer.c +