diff --git a/Drivers/Inc/ADC.h b/Drivers/Inc/ADC.h index 21bf348..577d328 100644 --- a/Drivers/Inc/ADC.h +++ b/Drivers/Inc/ADC.h @@ -10,5 +10,7 @@ typedef struct } MyADC_Struct_TypeDef; void MyADC_init(MyADC_Struct_TypeDef* myADC); - +void MyADC_start_conversion(ADC_TypeDef* ADC); +void MyADC_ActiveIT (ADC_TypeDef * ADC, char Prio, void (*IT_function)(void)); +int MyADC_result(ADC_TypeDef* ADC); #endif diff --git a/Drivers/Inc/UART.h b/Drivers/Inc/UART.h new file mode 100644 index 0000000..7877d90 --- /dev/null +++ b/Drivers/Inc/UART.h @@ -0,0 +1,10 @@ +#ifndef MYUART_H +#define MYUART_H +#include "stm32f10x.h" + +void MyUART_init(void); +void UART_send(char data); //à revoir +void MyUART_ActiveIT(char Prio, void (*IT_function)(void)); +char UART_receive(); + +#endif diff --git a/Drivers/Src/ADC.c b/Drivers/Src/ADC.c index 18adebe..4a5e096 100644 --- a/Drivers/Src/ADC.c +++ b/Drivers/Src/ADC.c @@ -1,26 +1,10 @@ #include "ADC.h" +void (*adc_ptr_func)(void); + void MyADC_init(MyADC_Struct_TypeDef* myADC) { MyGPIO_Struct_TypeDef Port_ADC; - RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; - if(myADC->ADC==ADC1) - { - RCC->APB2ENR |= 0x01<<9; - ADC1->CR2|= 0x01; // on active l'adc - ADC1->SQR1&= ~(0x0F<<20);// 1 convertion - ADC2->SQR3&= ~0x1F;// on met 0 la séquance 1 - ADC1->SQR3|= myADC->channel;// on indique le channel a convertir - } - else if(myADC->ADC==ADC2) - { - RCC->APB2ENR |= 0x01<<8; - ADC2->CR2|= 0x01; // on active l'adc - ADC2->SQR1&= ~(0x0F<<20);// 1 convertion - ADC2->SQR3&= ~0x1F;// on met 0 la séquance 1 - ADC2->SQR3|= myADC->channel;// on indique le channel a convertir - } - switch (myADC->channel) { case 0: @@ -120,18 +104,68 @@ void MyADC_init(MyADC_Struct_TypeDef* myADC) MyGPIO_Init(&Port_ADC); break; } -} - -int conversion(MyADC_Struct_TypeDef* myADC) + if(myADC->ADC==ADC1) { - if() - { - - } - ADC1->CR2 |= ADC_CR2_ADON; // lancement de la conversion - While(!(ADC1->SR & ADC_SR_EOC) ) {} // attente de la fin de conversion - ADC1->SR &= ~ADC_SR_EOC; // validation de la conversion - return ADC1->DR & ~((0x0F) << 12); // retour de la conversion + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; // validation horloge ADC1 + RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; // passage de l'horloge ADC1 à 12MHz + ADC1->CR2|= ADC_CR2_ADON; // démarrage ADC1 + ADC1->SQR1&= ADC_SQR1_L; // fixe le nombre de conversion à 1 + ADC1->SQR3|= myADC->channel; // indique la voie à convertir + ADC1->CR2 |= ADC_CR2_CAL; // dÈbut de la calibration + while ((ADC1->CR2 & ADC_CR2_CAL)); // attente de la fin de la calibration + } + else if(myADC->ADC==ADC2) + { + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; // validation horloge ADC1 + RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; // passage de l'horloge ADC1 à 12MHz + ADC2->CR2|= ADC_CR2_ADON; // démarrage ADC1 + ADC2->SQR1&= ADC_SQR1_L; // fixe le nombre de conversion à 1 + ADC2->SQR3|= myADC->channel; // indique la voie à convertir + ADC2->CR2 |= ADC_CR2_CAL; // dÈbut de la calibration + while ((ADC2->CR2 & ADC_CR2_CAL)); // attente de la fin de la calibration + } } +void MyADC_start_conversion(ADC_TypeDef* ADC) +{ + if(ADC==ADC1) + { + ADC1->CR2 |= ADC_CR2_ADON; // lancement de la conversion + } + else if(ADC==ADC2) + { + ADC2->CR2 |= ADC_CR2_ADON; // lancement de la conversion + } +} + +void ADC1_2_IRQHandler(void) +{ + ADC1->SR &= ~ADC_SR_EOC ; + ADC2->SR &= ~ADC_SR_EOC ; + if(adc_ptr_func!=0) + { + (*adc_ptr_func)(); + } +} + +void MyADC_ActiveIT (ADC_TypeDef * ADC, char Prio, void (*IT_function)(void)) +{ + ADC->CR1 |= ADC_CR1_EOCIE; + adc_ptr_func=IT_function; + NVIC->ISER[0] |= 0x01<IP[ADC1_2_IRQn] |= Prio << 4; + +} + +int MyADC_result(ADC_TypeDef* ADC) +{ + if (ADC==ADC1) + { + return ADC1->DR & ~((0x0F) << 12); // retour de la conversion + } + else if(ADC==ADC2) + { + return ADC2->DR & ~((0x0F) << 12); // retour de la conversion + } +} \ No newline at end of file diff --git a/Drivers/Src/TIMER.c b/Drivers/Src/TIMER.c index 07c123f..8b0fe3b 100644 --- a/Drivers/Src/TIMER.c +++ b/Drivers/Src/TIMER.c @@ -5,10 +5,10 @@ debordement stock fixer val prescaler+ autoreload(equivalent resolution) demarrage timer => CEN=1*/ -void (*ptr1_func)(void); -void (*ptr2_func)(void); -void (*ptr3_func)(void); -void (*ptr4_func)(void); +void (*tim_ptr1_func)(void); +void (*tim_ptr2_func)(void); +void (*tim_ptr3_func)(void); +void (*tim_ptr4_func)(void); void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer) { @@ -39,22 +39,22 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void) if(Timer==TIM1) { num_tim=TIM1_UP_IRQn; - ptr1_func=IT_function; + tim_ptr1_func=IT_function; } else if(Timer==TIM2) { num_tim=TIM2_IRQn; - ptr2_func=IT_function; + tim_ptr2_func=IT_function; } else if(Timer==TIM3) { num_tim=TIM3_IRQn; - ptr3_func=IT_function; + tim_ptr3_func=IT_function; } else if(Timer==TIM4) { num_tim=TIM4_IRQn; - ptr4_func=IT_function; + tim_ptr4_func=IT_function; } NVIC->ISER[0] |= 0x01<IP[num_tim] |= Prio << 4; @@ -63,36 +63,36 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void) void TIM2_IRQHandler (void) { - if(ptr2_func!=0) + if(tim_ptr2_func!=0) { - (*ptr2_func)(); + (*tim_ptr2_func)(); } TIM2->SR &= ~(1<<0) ; } void TIM3_IRQHandler (void) { - if(ptr3_func!=0) + if(tim_ptr3_func!=0) { - (*ptr3_func)(); + (*tim_ptr3_func)(); } TIM3->SR &= ~(1<<0) ; } void TIM4_IRQHandler (void) { - if(ptr4_func!=0) + if(tim_ptr4_func!=0) { - (*ptr4_func)(); + (*tim_ptr4_func)(); } TIM4->SR &= ~(1<<0) ; } void TIM1_UP_IRQHandler (void) // à vérifier { - if(ptr1_func!=0) + if(tim_ptr1_func!=0) { - (*ptr1_func)(); + (*tim_ptr1_func)(); } TIM1->SR &= ~(1<<0) ; } diff --git a/Drivers/Src/UART.c b/Drivers/Src/UART.c new file mode 100644 index 0000000..fea85ee --- /dev/null +++ b/Drivers/Src/UART.c @@ -0,0 +1,44 @@ +#include "UART.h" + +void (*uart_ptr_func)(void); +char buffer[1000]={0}; + +void MyUART_init(void) // que pour du 9600 bauds +{ + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // validation horloge USART1 + USART1->CR1 |= USART_CR1_UE; // Activation de l'USART + USART1->CR1 &= ~USART_CR1_M; // Choix d'une taille de 8 bits de données + USART1->CR2 &= USART_CR2_STOP; // Choix d'un seul bit de stop + USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps //valeurs trouvé p804 + USART1->BRR |= 75; // Fixe le baud rate à 9600bps + USART1->CR1 |= USART_CR1_TE; // Envoi de la première trame d'attente +} + +void UART_send(char data) +{ + USART1->DR |= data; // Ecriture de la donnée dans le registre DR + while(!(USART1->SR & USART_SR_TC)) {} // Attente de la fin de transmission +} + +void MyUART_ActiveIT(char Prio, void (*IT_function)(void)) +{ + USART1->CR1 |= USART_CR1_RXNEIE; + NVIC->ISER[1] |= 0x01<<(USART1_IRQn%32); + NVIC->IP[USART1_IRQn] |= Prio << 4; +} + +void USART1_IRQHandler() +{ + USART1->SR &= ~USART_SR_RXNE; + if(uart_ptr_func!=0) + { + (*uart_ptr_func)(); + } +} + +char UART_receive() +{ + char carac; + carac = USART1->DR; + return carac; +} diff --git a/Projet_DevDrivers/Sources/Principal.c b/Projet_DevDrivers/Sources/Principal.c deleted file mode 100644 index 84c63ad..0000000 --- a/Projet_DevDrivers/Sources/Principal.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "stm32f10x.h" -#include "GPIO.h" -#include "TIMER.h" - - - -void Mafonction_IT (void); -MyGPIO_Struct_TypeDef PA5; -MyGPIO_Struct_TypeDef PC13; -MyTimer_Struct_TypeDef timer2; -//PA5 LED -//PC13 Bouton - -int main ( void ) -{ - - - while(1) - { - - } - -} - - - -void Mafonction_IT (void) -{ - MyGPIO_Toggle(PA5.GPIO,5); -} diff --git a/Projet_DevDrivers/RTE/Device/STM32F103RB/RTE_Device.h b/Projet_voile/RTE/Device/STM32F103RB/RTE_Device.h similarity index 100% rename from Projet_DevDrivers/RTE/Device/STM32F103RB/RTE_Device.h rename to Projet_voile/RTE/Device/STM32F103RB/RTE_Device.h diff --git a/Projet_DevDrivers/RTE/Device/STM32F103RB/startup_stm32f10x_md.s b/Projet_voile/RTE/Device/STM32F103RB/startup_stm32f10x_md.s similarity index 100% rename from Projet_DevDrivers/RTE/Device/STM32F103RB/startup_stm32f10x_md.s rename to Projet_voile/RTE/Device/STM32F103RB/startup_stm32f10x_md.s diff --git a/Projet_DevDrivers/RTE/Device/STM32F103RB/system_stm32f10x.c b/Projet_voile/RTE/Device/STM32F103RB/system_stm32f10x.c similarity index 100% rename from Projet_DevDrivers/RTE/Device/STM32F103RB/system_stm32f10x.c rename to Projet_voile/RTE/Device/STM32F103RB/system_stm32f10x.c diff --git a/Projet_DevDrivers/RTE/_R_el/RTE_Components.h b/Projet_voile/RTE/_R_el/RTE_Components.h similarity index 100% rename from Projet_DevDrivers/RTE/_R_el/RTE_Components.h rename to Projet_voile/RTE/_R_el/RTE_Components.h diff --git a/Projet_DevDrivers/RTE/_Simul_/RTE_Components.h b/Projet_voile/RTE/_Simul_/RTE_Components.h similarity index 100% rename from Projet_DevDrivers/RTE/_Simul_/RTE_Components.h rename to Projet_voile/RTE/_Simul_/RTE_Components.h diff --git a/Projet_DevDrivers/RTE/_Target_1/RTE_Components.h b/Projet_voile/RTE/_Target_1/RTE_Components.h similarity index 100% rename from Projet_DevDrivers/RTE/_Target_1/RTE_Components.h rename to Projet_voile/RTE/_Target_1/RTE_Components.h diff --git a/Projet_voile/Sources/Principal.c b/Projet_voile/Sources/Principal.c new file mode 100644 index 0000000..5efa581 --- /dev/null +++ b/Projet_voile/Sources/Principal.c @@ -0,0 +1,38 @@ +#include "stm32f10x.h" +#include "GPIO.h" +#include "TIMER.h" +#include "ADC.h" +#include "UART.h" + +int val_adc=0; +MyGPIO_Struct_TypeDef PA5; //PA5 LED +MyGPIO_Struct_TypeDef PC13; //PC13 Bouton +MyTimer_Struct_TypeDef timer2; +MyADC_Struct_TypeDef myADC; +void Mafonction_IT (void); +void Mafonction_IT2(void); + +int main ( void ) +{ + myADC.ADC=ADC1; + myADC.channel=2; + MyADC_init(&myADC); + MyADC_ActiveIT(myADC.ADC,0,&Mafonction_IT2); + MyADC_start_conversion(myADC.ADC); + while(1) + { + } + +} + + + +void Mafonction_IT (void) +{ + MyGPIO_Toggle(PA5.GPIO,5); +} + +void Mafonction_IT2 (void) +{ + val_adc=MyADC_result(myADC.ADC); +} diff --git a/Projet_DevDrivers/TP1.uvoptx b/Projet_voile/TP1.uvoptx similarity index 89% rename from Projet_DevDrivers/TP1.uvoptx rename to Projet_voile/TP1.uvoptx index ece801c..9b7ddad 100644 --- a/Projet_DevDrivers/TP1.uvoptx +++ b/Projet_voile/TP1.uvoptx @@ -125,7 +125,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=733,260,1154,687,0)(121=-1,-1,-1,-1,0)(122=1345,565,1766,992,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1189,292,1783,1043,1)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=1184,109,1560,666,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=733,260,1154,687,0)(121=-1,-1,-1,-1,0)(122=1345,565,1766,992,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=335,254,929,1005,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1126,210,1574,624,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=298,316,901,1067,0)(151=-1,-1,-1,-1,0) 0 @@ -138,7 +138,24 @@ UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)) - + + + 0 + 0 + 37 + 1 +
134218114
+ 0 + 0 + 0 + 0 + 0 + 1 + .\Sources\Principal.c + + \\TP1\Sources/Principal.c\37 +
+
0 @@ -147,7 +164,7 @@ 1 1 0 - 0 + 1 0 0 1 @@ -442,6 +459,18 @@ 0 0 + + 1 + 5 + 1 + 1 + 0 + 0 + ..\Drivers\Src\UART.c + UART.c + 0 + 0 + diff --git a/Projet_DevDrivers/TP1.uvprojx b/Projet_voile/TP1.uvprojx similarity index 98% rename from Projet_DevDrivers/TP1.uvprojx rename to Projet_voile/TP1.uvprojx index 9e4df6f..4c5f056 100644 --- a/Projet_DevDrivers/TP1.uvprojx +++ b/Projet_voile/TP1.uvprojx @@ -403,6 +403,11 @@ 1 ..\Drivers\Src\ADC.c + + UART.c + 1 + ..\Drivers\Src\UART.c + @@ -810,6 +815,11 @@ 1 ..\Drivers\Src\ADC.c + + UART.c + 1 + ..\Drivers\Src\UART.c +