22.03 ADC wip

This commit is contained in:
Clement Marce 2023-03-22 16:33:46 +01:00
parent 73d9e8fdb2
commit 541f57dbef
6 changed files with 87 additions and 33 deletions

View file

@ -0,0 +1,18 @@
#ifndef MYADC_H
#define MYADC_H
#include "stm32f10x.h"
#include "Driver_GPIO.h"
typedef struct
{
ADC_TypeDef * ADC;
char Channel;
} MyADC_Struct_TypeDef;
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC);
void MyADC_Base_Start(ADC_TypeDef * ADC);
void MyADC_Base_Stop(ADC_TypeDef * ADC);
#endif

View file

@ -15,10 +15,4 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
void MyTimer_Base_Start(TIM_TypeDef * Timer); void MyTimer_Base_Start(TIM_TypeDef * Timer);
void MyTimer_Base_Stop(TIM_TypeDef * Timer); void MyTimer_Base_Stop(TIM_TypeDef * Timer);
/*#define MyTimer_Base_Start(Timer)
#define MyTimer_Base_Stop(Timer)
*/
#endif #endif

View file

@ -0,0 +1,23 @@
#include "Driver_ADC.h"
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; //Division par 6 de la clock (72MHz) pour l'ADC (14MHz max)
if(ADC->ADC == ADC1){
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable Clock ADC1
ADC1->CR2= ADC_CR2_ADON; //Enable ADC1
ADC1->SQR1&= ADC_SQR1_L;
ADC1->SQR3|= 8;
}else{
}
}
void MyADC_Base_Start(ADC_TypeDef * ADC){
}
void MyADC_Base_Stop(ADC_TypeDef * ADC){
}

View file

@ -443,6 +443,30 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>5</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Include\Driver_ADC.h</PathWithFileName>
<FilenameWithoutPath>Driver_ADC.h</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Sources\Driver_ADC.c</PathWithFileName>
<FilenameWithoutPath>Driver_ADC.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group> </Group>
<Group> <Group>
@ -453,7 +477,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>2</GroupNumber> <GroupNumber>2</GroupNumber>
<FileNumber>5</FileNumber> <FileNumber>7</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>1</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>

View file

@ -403,6 +403,16 @@
<FileType>5</FileType> <FileType>5</FileType>
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath> <FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
</File> </File>
<File>
<FileName>Driver_ADC.h</FileName>
<FileType>5</FileType>
<FilePath>..\Drivers\Include\Driver_ADC.h</FilePath>
</File>
<File>
<FileName>Driver_ADC.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -820,6 +830,16 @@
<FileType>5</FileType> <FileType>5</FileType>
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath> <FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
</File> </File>
<File>
<FileName>Driver_ADC.h</FileName>
<FileType>5</FileType>
<FilePath>..\Drivers\Include\Driver_ADC.h</FilePath>
</File>
<File>
<FileName>Driver_ADC.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>

View file

@ -2,30 +2,14 @@
#include "Driver_Timer.h" #include "Driver_Timer.h"
int main (void){ int main (void){
//Déclaration d'une LED et d'un BP par structure GPIO
MyGPIO_Struct_TypeDef LED;
MyGPIO_Struct_TypeDef BP;
//Déclaration d'un Timer 500 ms //Déclaration d'un Timer 500 ms
MyTimer_Struct_TypeDef TIM500ms; MyTimer_Struct_TypeDef TIM500ms;
//Config LED PA5
LED.GPIO_Conf = Out_Ppull;
LED.GPIO_Pin = 5;
LED.GPIO = GPIOA;
MyGPIO_Init (&LED) ;
//Config BP PC13
BP.GPIO_Conf = In_Floating;
BP.GPIO_Pin = 13;
BP.GPIO = GPIOC;
//Init BP & LED
MyGPIO_Init (&LED);
MyGPIO_Init (&BP);
//Init Timer 2 et Test //Init Timer 2 et Test
TIM500ms.Timer = TIM2; TIM500ms.Timer = TIM2;
TIM500ms.PSC = 0xD2F0; // =0.5ms(calculé à partir de la fréquence du micro) TIM500ms.PSC = 0xD2F0; // =0.5ms(calculé à partir de la fréquence du micro)
TIM500ms.ARR = 1000; TIM500ms.ARR = 1000;
MyTimer_Base_Init(&TIM500ms); MyTimer_Base_Init(&TIM500ms);
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
//TIM2->DIER |= TIM_DIER_UIE ; //TIM2->DIER |= TIM_DIER_UIE ;
NVIC->ISER[0] |= 1<<TIM2_IRQn ; //INTERRUPTION COEUR NVIC->ISER[0] |= 1<<TIM2_IRQn ; //INTERRUPTION COEUR
@ -33,16 +17,7 @@ int main (void){
MyTimer_Base_Start(TIM500ms.Timer); MyTimer_Base_Start(TIM500ms.Timer);
//Boucle infinie de la réponse de la LED à l'état BP //Boucle infinie de la réponse de la LED à l'état BP
while(1){ while(1){
// if (MyGPIO_Read(BP.GPIO,BP.GPIO_Pin)==0){
// MyGPIO_Set(LED.GPIO,LED.GPIO_Pin);
// }else{
// MyGPIO_Reset(LED.GPIO,LED.GPIO_Pin);
// }
} }
} }