This commit is contained in:
Cedric Chanfreau 2023-04-11 14:54:07 +02:00
commit 7163e05d17
4 changed files with 55 additions and 100 deletions

View file

@ -2,29 +2,29 @@
#include "Driver_GPIO.h"
void (*PtrfctADC)(void); //Déclaration du pointeur de fonction ADC
void (*PtrfctADC)(void); /* Déclaration du pointeur de fonction ADC pour l'interrupt */
//---------------------INIT-------------------//
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){
MyGPIO_Struct_TypeDef * GPIO_ADC; //Déclaration du GPIO de l'ADC
MyGPIO_Struct_TypeDef * GPIO_ADC; /* Déclaration du GPIO lié à 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
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; /*Division par 6 de la clock (72MHz) pour l'ADC (12MHz) car clock max ADC : 14MHz */
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; /* Start clock de l'ADC1 */
GPIO_ADC->GPIO = GPIOC; //Initialisation du GPIO de l'ADC
GPIO_ADC->GPIO = GPIOC; /* Initialisation du GPIO lié à 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
ADC1->SQR1 &= ADC_SQR1_L; /* Fixation du nombre de conversion à 1 */
ADC1->SQR3|= ADC->Channel; /* Choix de 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
MyADC_Base_Start(ADC->ADC); /* Sart ADC1 et Horloge ADC1 */
}
@ -36,25 +36,25 @@ void MyADC_Base_Start(ADC_TypeDef * ADC){
//------------------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é
/* 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
(*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
ADC1->SR &= ~ADC_SR_EOC; /* RAZ du flag de fin de conversion */
}
//--------------------DATA--------------------//
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC){
return ADC1->DR & ~((0x0F)<<12); //Retour de la conversion de l'ADC
return ADC1->DR & ~((0x0F)<<12); /* Récuperation du résultat de la conversion de l'ADC */
}
//-------------------POINTEUR-----------------//
void MyADC_Init_Periph (void (*fct)(void)){
PtrfctADC=fct; //Affectation du pointeur de fonction ADC
PtrfctADC=fct; /* Affectation du pointeur de fonction ADC */
}

View file

@ -5,26 +5,26 @@
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
{
/* Activation of the GPIO port specific clock */
/* Activation de la clock liée au GPIO sélectionné */
if (GPIOStructPtr->GPIO == GPIOA)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
}
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
}
else if (GPIOStructPtr->GPIO == GPIOB)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
}
}
else if (GPIOStructPtr->GPIO == GPIOC)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
}
}
else if (GPIOStructPtr->GPIO == GPIOD)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN;
}
/* Reset, and then configuration writing of the selected GPIO Pin */
/* Reset & configuration de la pin avec le mode adéquat */
if(GPIOStructPtr->GPIO_Pin <= 8)
{
GPIOStructPtr->GPIO->CRL &= ~0xF<<(4*(GPIOStructPtr->GPIO_Pin));
@ -36,6 +36,7 @@ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf)<<(4*((GPIOStructPtr->GPIO_Pin)%8));
}
/* Ecriture de l'ODR pour choisir entre pulldown & pushpull*/
if(GPIOStructPtr->GPIO_Conf == (char)In_PullDown)
{
GPIOStructPtr->GPIO->ODR &= ~(0x1<<(GPIOStructPtr->GPIO_Pin));
@ -49,7 +50,8 @@ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
//----------------------------READ--------------------------//
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
int etatbit;
//On vérifie si la valeur lue dans l'IDR est un 0 ou un 1
/* Verification de la valeur de l'IDR */
if((GPIO->IDR & (1<<GPIO_Pin))!=0){
etatbit = 1;
}
@ -61,13 +63,16 @@ int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
//---------------------SET-------------------//
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
/*Ecriture du 1 sur le numéro de la pin dans le registre BSRR*/
GPIO->BSRR |= (1 << GPIO_Pin);
}
//---------------------RESET-----------------//
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
/*Ecriture du 1 sur le numéro de la pin dans le registre BRR*/
GPIO->BRR = (1 << GPIO_Pin);
//Pas besoin de | puisque les 0 n'impactent pas la fonction reset
}
//---------------------TOGGLE-----------------//

View file

@ -2,6 +2,8 @@
//-----------------------INITIALISATION TIMER---------------------//
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
/* Activation de la clock liée au TIMER sélectionné */
if(Timer->Timer == TIM1){
//RCC->APB2ENR |= 0x0001<<11;
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
@ -19,6 +21,7 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
}
/* Load des valeurs de l'ARR et du PSC pour définir la période de comptage du TIMER et sa limite*/
Timer->Timer->ARR = Timer->ARR;
Timer->Timer->PSC = Timer->PSC;
@ -27,20 +30,21 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
//-----------------------START----------------------//
void MyTimer_Base_Start(TIM_TypeDef * Timer){
Timer->CR1 |= TIM_CR1_CEN; //Masque OU pour placer un 1 décalé avec des 0
Timer->CR1 |= TIM_CR1_CEN; //* Masque OU pour placer un 1 décalé avec des 0 */
}
//------------------------STOP----------------------//
void MyTimer_Base_Stop(TIM_TypeDef * Timer){
Timer->CR1 |= ~TIM_CR1_CEN; //Masque ET pour placer un 0 décalé avec des 1 (~)
Timer->CR1 |= ~TIM_CR1_CEN; /* Masque ET pour placer un 0 décalé avec des 1 (~) */
}
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){
Timer->Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; //Configuration du canal CH1
Timer->Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2; // Ajouter 110 aux bits OC1M (registre CCMR1)
Timer->Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; /* Configuration du canal CH1 */
Timer->Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2; /* Ajouter 110 aux bits OC1M (registre CCMR1) */
Timer->Timer->CCER |= TIM_CCER_CC1E; // Canal CH1 validé par bit CC1E (registre CCER)
Timer->Timer->CR1 |= TIM_CR1_CEN; // Lancement du timer
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
Timer->Timer->CCER |= TIM_CCER_CC1E; /* Canal CH1 validé par bit CC1E (registre CCER) */
Timer->Timer->CR1 |= TIM_CR1_CEN; /* Lancement du timer */
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; /* Fixer la durée à 20% */
}

View file

@ -1,72 +1,18 @@
# Projet Voilier
## 1) GPIO
## Equipe 4
* Clement MARCE
* Louis ROUSSET
* Cedric CHANFREAU
### a) MyGPIO_Init
![Name](.\INSA\Microcontrôleur\README_picture)
![Image](file:///U:/INSA/Microcontr%C3%B4leur/README_picture/APB2ENR.png)
### b) MyGPIO_Read
### c) MyGPIO_Set
### d) MyGPIO_Reset
### e) MyGPIO_Toggle
## 2) Timer
### a) MyTimer_Init
### b) MyTimer_Start
### c) MyTimer_Stop
### d) TIM1_Interrupt
### e) TIM1_IRQHandler
## 3) PWM
### a) MyTimer_PWM
## 4) ADC
### a) MyADC_Init
### b) MyADC_Init_Periph
### c) MyADC_Result
### d) MyADC_Start
### e) MyADC_Base_Interuption
### f) ADC1_2_IRQHandler
## 5) UART
### a) UART_init
### b) UART_send
### c) UART_read
### d) UART_interruption
### e) USART1_IRQHandler
### f) UART_InitGPIO
## 6) Plateau
### a) Plateau_init
### b) MyMotor_ChangeDirection
## 7) Girouette
## Réalisation des drivers :
* [GPIOS](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Sources/Driver_GPIO.c) //Done
* [TIMERS](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Sources/Driver_Timer.c) //Done
* [PWM](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Sources/Driver_Timer.c) //Done (Cédric)
* [ADC](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Sources/Driver_ADC.c) //Done (Clement+Louis)
* [UART](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Sources/Driver_UART.c) //Done (Cédric)
## Réalisation des différentes fonctions du bateau :
* [Girouette](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Voilier_fonction/Girouette.c) //Work in progress (Clement)
* [Plateau](https://git.etud.insa-toulouse.fr/marce/Voilier/src/branch/master/Drivers/Voilier_fonction/Plateau.c) //Need to test (Cédric)