Compare commits
2 commits
ed00a94bee
...
6fb6599efe
Author | SHA1 | Date | |
---|---|---|---|
6fb6599efe | |||
f98a22a727 |
6 changed files with 62 additions and 24 deletions
|
@ -1,21 +1,60 @@
|
||||||
#ifndef MYADC_H
|
#include "Driver_ADC.h"
|
||||||
#define MYADC_H
|
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
void (*PtrfctADC)(void); //Déclaration du pointeur de fonction ADC
|
||||||
ADC_TypeDef * ADC;
|
|
||||||
char Channel;
|
//---------------------INIT-------------------//
|
||||||
} MyADC_Struct_TypeDef;
|
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);
|
//--------------------START-------------------//
|
||||||
void MyADC_Base_Start(ADC_TypeDef * ADC);
|
void MyADC_Base_Start(ADC_TypeDef * ADC){
|
||||||
void MyADC_Base_Stop(ADC_TypeDef * ADC);
|
ADC1->CR2 |= ADC_CR2_ADON;
|
||||||
void MyADC_Base_Interuption(ADC_TypeDef * ADC);
|
}
|
||||||
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC);
|
|
||||||
void MyADC_Init_Periph (void (*fct)(void));
|
|
||||||
|
|
||||||
#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
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "Driver_Timer.h"
|
#include "Driver_Timer.h"
|
||||||
#include "Driver_Timer.c"
|
|
||||||
#include "Driver_UART.h"
|
#include "Driver_UART.h"
|
||||||
#include "Plateau.h"
|
#include "Plateau.h"
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
|
@ -22,9 +21,9 @@ void Plateau_init(void)
|
||||||
MyTimer_Base_Init(&Timer);
|
MyTimer_Base_Init(&Timer);
|
||||||
MyGPIO_Init(&Pin_Sens);
|
MyGPIO_Init(&Pin_Sens);
|
||||||
|
|
||||||
MyTimer_PWM(TIM3, 50);
|
//MyTimer_PWM(TIM3, 50);
|
||||||
|
|
||||||
MyTimer_Base_Start(Timer);
|
//MyTimer_Base_Start(Timer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -426,7 +426,7 @@
|
||||||
<GroupNumber>1</GroupNumber>
|
<GroupNumber>1</GroupNumber>
|
||||||
<FileNumber>1</FileNumber>
|
<FileNumber>1</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\Drivers\Sources\Driver_GPIO.c</PathWithFileName>
|
<PathWithFileName>..\Drivers\Sources\Driver_GPIO.c</PathWithFileName>
|
||||||
|
@ -462,10 +462,10 @@
|
||||||
<GroupNumber>1</GroupNumber>
|
<GroupNumber>1</GroupNumber>
|
||||||
<FileNumber>4</FileNumber>
|
<FileNumber>4</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>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</PathWithFileName>
|
<PathWithFileName>..\Drivers\Sources\Driver_ADC.c</PathWithFileName>
|
||||||
<FilenameWithoutPath>Driver_ADC.c</FilenameWithoutPath>
|
<FilenameWithoutPath>Driver_ADC.c</FilenameWithoutPath>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<bShared>0</bShared>
|
<bShared>0</bShared>
|
||||||
|
|
|
@ -401,7 +401,7 @@
|
||||||
<File>
|
<File>
|
||||||
<FileName>Driver_ADC.c</FileName>
|
<FileName>Driver_ADC.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -838,7 +838,7 @@
|
||||||
<File>
|
<File>
|
||||||
<FileName>Driver_ADC.c</FileName>
|
<FileName>Driver_ADC.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_ADC.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
BIN
README_picture/APB2ENR.png
Normal file
BIN
README_picture/APB2ENR.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
README_picture/Thumbs.db
Normal file
BIN
README_picture/Thumbs.db
Normal file
Binary file not shown.
Loading…
Reference in a new issue