Added battery and initBattery functions, using external variable uartCool

This commit is contained in:
Yohan Boujon 2023-04-07 15:28:30 +02:00
parent 24cd95c9e3
commit 1874f666d4
10 changed files with 118 additions and 12 deletions

View file

@ -1,8 +1,8 @@
#include "adc.h" #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 */ pFncADC = ptrFonction; /* affectation du pointeur */
} }
@ -38,7 +38,7 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
void ADC1_2_IRQHandler(void) void ADC1_2_IRQHandler(void)
{ {
if (pFncADC != 0) if (pFncADC != 0)
(*pFncADC) (); /* appel indirect de la fonction */ (*pFncADC) (ADC1->DR); /* appel indirect de la fonction */
MyADC_Base_Start(ADC1); MyADC_Base_Start(ADC1);
ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant <20>tre effectu<74>e. ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant <20>tre effectu<74>e.
} }

View file

@ -23,7 +23,7 @@ typedef struct
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr); void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr);
void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio); 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); MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC);
#define MyADC_Base_Start(ADC) (ADC->CR2 |= ADC_CR2_SWSTART) #define MyADC_Base_Start(ADC) (ADC->CR2 |= ADC_CR2_SWSTART)

View file

@ -3,7 +3,7 @@
#include "MySPI.h" #include "MySPI.h"
#include "gpio.h" #include "gpio.h"
void accelerometre() void accelerometre(void)
{ {
int dataX ; int dataX ;
float GX ; float GX ;

View file

@ -2,7 +2,7 @@
#define INC_ACCELEROMETER_H_ #define INC_ACCELEROMETER_H_
#include "../driver/MySPI.h" #include "../driver/MySPI.h"
void accelerometre(); void accelerometre(void);
#endif #endif

26
implementation/battery.c Normal file
View file

@ -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);
}

8
implementation/battery.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef BATTERY_H
#define BATTERY_H
#include "stm32f10x.h"
void battery(uint32_t data);
void initBattery(void);
#endif

View file

@ -6,7 +6,6 @@ MyUART_Struct_Typedef uartCool = {USART1,9600,lengthBit8,parityNone,stopBit1};
void remote(uint8_t data) void remote(uint8_t data)
{ {
MyUART_Send(&uartCool,data);
int8_t signedData = (int8_t)data; int8_t signedData = (int8_t)data;
if(signedData >= 0) if(signedData >= 0)
{ {

View file

@ -4,6 +4,8 @@
#include "motoreducteur.h" #include "motoreducteur.h"
#include "rtc.h" #include "rtc.h"
#include "remote.h" #include "remote.h"
#include "battery.h"
#include "accelerometer.h"
void initImplementation(void); void initImplementation(void);
@ -27,4 +29,5 @@ void initImplementation(void)
MyMotor_ChangeDirection(HORAIRE); MyMotor_ChangeDirection(HORAIRE);
MyRTC_Init(); MyRTC_Init();
accelerometre(); accelerometre();
initBattery();
} }

View file

@ -272,6 +272,26 @@
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon> <pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMRTXEVENTFLAGS</Key>
<Name>-L70 -Z18 -C0 -M0 -T1</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>DLGTARM</Key>
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMDBGFLAGS</Key>
<Name></Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>DLGUARM</Key>
<Name>(105=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key> <Key>ST-LINKIII-KEIL_SWO</Key>
@ -290,12 +310,12 @@
<DebugFlag> <DebugFlag>
<trace>0</trace> <trace>0</trace>
<periodic>0</periodic> <periodic>0</periodic>
<aLwin>0</aLwin> <aLwin>1</aLwin>
<aCover>0</aCover> <aCover>0</aCover>
<aSer1>0</aSer1> <aSer1>0</aSer1>
<aSer2>0</aSer2> <aSer2>0</aSer2>
<aPa>0</aPa> <aPa>0</aPa>
<viewmode>0</viewmode> <viewmode>1</viewmode>
<vrSel>0</vrSel> <vrSel>0</vrSel>
<aSym>0</aSym> <aSym>0</aSym>
<aTbox>0</aTbox> <aTbox>0</aTbox>
@ -326,6 +346,12 @@
<pszMrulep></pszMrulep> <pszMrulep></pszMrulep>
<pSingCmdsp></pSingCmdsp> <pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<SystemViewers>
<Entry>
<Name>System Viewer\ADC1</Name>
<WinId>35905</WinId>
</Entry>
</SystemViewers>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>0</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>
@ -414,7 +440,7 @@
<GroupNumber>2</GroupNumber> <GroupNumber>2</GroupNumber>
<FileNumber>6</FileNumber> <FileNumber>6</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\driver\adc.c</PathWithFileName> <PathWithFileName>..\driver\adc.c</PathWithFileName>
@ -478,6 +504,30 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>11</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\battery.c</PathWithFileName>
<FilenameWithoutPath>battery.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>12</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\accelerometer.c</PathWithFileName>
<FilenameWithoutPath>accelerometer.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group> </Group>
<Group> <Group>

View file

@ -443,6 +443,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\implementation\remote.c</FilePath> <FilePath>..\implementation\remote.c</FilePath>
</File> </File>
<File>
<FileName>battery.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\battery.c</FilePath>
</File>
<File>
<FileName>accelerometer.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\accelerometer.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -890,6 +900,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\implementation\remote.c</FilePath> <FilePath>..\implementation\remote.c</FilePath>
</File> </File>
<File>
<FileName>battery.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\battery.c</FilePath>
</File>
<File>
<FileName>accelerometer.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\accelerometer.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>