Compare commits

...

2 commits

Author SHA1 Message Date
6fb6599efe Merge branch 'master' of https://git.etud.insa-toulouse.fr/marce/Voilier 2023-04-11 12:11:55 +02:00
f98a22a727 Image 2023-04-11 12:10:20 +02:00
6 changed files with 62 additions and 24 deletions

View file

@ -1,21 +1,60 @@
#ifndef MYADC_H
#define MYADC_H
#include "stm32f10x.h"
#include "Driver_ADC.h"
#include "Driver_GPIO.h"
typedef struct
{
ADC_TypeDef * ADC;
char Channel;
} MyADC_Struct_TypeDef;
void (*PtrfctADC)(void); //Déclaration du pointeur de fonction ADC
//---------------------INIT-------------------//
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){
MyGPIO_Struct_TypeDef * GPIO_ADC; //Déclaration du GPIO de l'ADC
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; //Division par 6 de la clock (72MHz) pour l'ADC (12MHz)
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Start clock ADC1
GPIO_ADC->GPIO = GPIOC; //Initialisation du GPIO de l'ADC
GPIO_ADC->GPIO_Conf = In_Analog;
GPIO_ADC->GPIO_Pin = 0;
MyGPIO_Init(GPIO_ADC);
ADC1->SQR1 &= ADC_SQR1_L; //fixe le nombre de conversion à 1
ADC1->SQR3|= ADC->Channel; //indique la voie à convertir
ADC1->CR2 |= ADC_CR2_EXTTRIG; //activation du trigger externe
ADC1->CR2 |= ADC_CR2_EXTSEL; //event externe choisis : SWSTART
MyADC_Base_Start(ADC->ADC); //Sart ADC1 et Horloge ADC1
}
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC);
void MyADC_Base_Start(ADC_TypeDef * ADC);
void MyADC_Base_Stop(ADC_TypeDef * ADC);
void MyADC_Base_Interuption(ADC_TypeDef * ADC);
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC);
void MyADC_Init_Periph (void (*fct)(void));
//--------------------START-------------------//
void MyADC_Base_Start(ADC_TypeDef * ADC){
ADC1->CR2 |= ADC_CR2_ADON;
}
#endif
//------------------INTERRUPTION--------------//
void MyADC_Base_Interuption(ADC_TypeDef * ADC){
//Activation du trigger externe
ADC->CR1 |= ADC_CR1_EOCIE; //Interruption de l'ADC autorisée
NVIC->ISER[0] |= (0x1<<ADC1_2_IRQn); //Interruption active au niveau NVIC
NVIC->IP[ADC1_2_IRQn] |= 1<<4; //Affectation du niveau de priorité
}
//--------------------HANDLER-----------------//
void ADC1_2_IRQHandler (void) {
(*PtrfctADC)(); //Appel de la fonction pointée par le pointeur fonction ADC
MyADC_Base_Start(ADC1);
ADC1->SR &= ~ADC_SR_EOC; //RAZ du flag end of conversion
}
//--------------------DATA--------------------//
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC){
return ADC1->DR & ~((0x0F)<<12); //Retour de la conversion de l'ADC
}
//-------------------POINTEUR-----------------//
void MyADC_Init_Periph (void (*fct)(void)){
PtrfctADC=fct; //Affectation du pointeur de fonction ADC
}

View file

@ -1,5 +1,4 @@
#include "Driver_Timer.h"
#include "Driver_Timer.c"
#include "Driver_UART.h"
#include "Plateau.h"
#include "Driver_GPIO.h"
@ -22,9 +21,9 @@ void Plateau_init(void)
MyTimer_Base_Init(&Timer);
MyGPIO_Init(&Pin_Sens);
MyTimer_PWM(TIM3, 50);
//MyTimer_PWM(TIM3, 50);
MyTimer_Base_Start(Timer);
//MyTimer_Base_Start(Timer);
}

View file

@ -426,7 +426,7 @@
<GroupNumber>1</GroupNumber>
<FileNumber>1</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Sources\Driver_GPIO.c</PathWithFileName>
@ -462,10 +462,10 @@
<GroupNumber>1</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</PathWithFileName>
<PathWithFileName>..\Drivers\Sources\Driver_ADC.c</PathWithFileName>
<FilenameWithoutPath>Driver_ADC.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>

View file

@ -401,7 +401,7 @@
<File>
<FileName>Driver_ADC.c</FileName>
<FileType>1</FileType>
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
</File>
</Files>
</Group>
@ -838,7 +838,7 @@
<File>
<FileName>Driver_ADC.c</FileName>
<FileType>1</FileType>
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
</File>
</Files>
</Group>

BIN
README_picture/APB2ENR.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
README_picture/Thumbs.db Normal file

Binary file not shown.