From c404ceeab2f941c2af42efb52667f3a56d96627f Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 22 Mar 2023 16:56:22 +0100 Subject: [PATCH 1/9] PWM Done --- Drivers/Sources/Driver_Timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Drivers/Sources/Driver_Timer.c b/Drivers/Sources/Driver_Timer.c index 678672a..6784afe 100644 --- a/Drivers/Sources/Driver_Timer.c +++ b/Drivers/Sources/Driver_Timer.c @@ -42,5 +42,5 @@ void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){ 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->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20% } From 4b6629eb48ce4dc50050df8b86ba06efcbfbbb72 Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 27 Mar 2023 17:00:49 +0200 Subject: [PATCH 2/9] UART init and send --- Drivers/Include/Driver_UART.h | 11 +++++++ Drivers/Sources/Driver_UART.c | 21 +++++++++++++ GPIO_Test/GPIO_Test.uvoptx | 59 ++++++++++++++++++++++++----------- GPIO_Test/GPIO_Test.uvprojx | 22 ++++--------- GPIO_Test/Sources/Main.c | 16 +++++++++- 5 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 Drivers/Include/Driver_UART.h create mode 100644 Drivers/Sources/Driver_UART.c diff --git a/Drivers/Include/Driver_UART.h b/Drivers/Include/Driver_UART.h new file mode 100644 index 0000000..77556d9 --- /dev/null +++ b/Drivers/Include/Driver_UART.h @@ -0,0 +1,11 @@ +#ifndef MYUART_H +#define MYUART_H + +#include "stm32f10x.h" + +void UART_send(char data); +void UART_init(); + + + +#endif diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c new file mode 100644 index 0000000..396c0c8 --- /dev/null +++ b/Drivers/Sources/Driver_UART.c @@ -0,0 +1,21 @@ +#include "Driver_UART.h" + + +void UART_init() + { + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1 + USART1->CR1 |= USART_CR1_UE; // Activer l'USART + USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée + USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop + USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps + USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire + //USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600 + USART1->CR1 |= USART_CR1_TE; + } + +void UART_send(char data) + { + USART1->DR |= data; + while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission + } + \ No newline at end of file diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index cfed698..66c8b4b 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(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=-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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=949,269,1397,683,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) 0 @@ -143,7 +143,40 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - + + + 0 + 0 + 47 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Sources\Main.c + + +
+ + 1 + 0 + 47 + 1 +
134219276
+ 0 + 0 + 0 + 0 + 0 + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c + + \\GPIO_Test\Sources/Main.c\47 +
+
0 @@ -416,24 +449,12 @@ 1 3 - 5 - 0 + 1 + 1 0 0 - ..\Drivers\Include\Driver_GPIO.h - Driver_GPIO.h - 0 - 0 - - - 1 - 4 - 5 - 0 - 0 - 0 - ..\Drivers\Include\Driver_Timer.h - Driver_Timer.h + ..\Drivers\Sources\Driver_UART.c + Driver_UART.c 0 0 @@ -447,7 +468,7 @@ 0 2 - 5 + 4 1 1 0 diff --git a/GPIO_Test/GPIO_Test.uvprojx b/GPIO_Test/GPIO_Test.uvprojx index b649e18..1c6256e 100644 --- a/GPIO_Test/GPIO_Test.uvprojx +++ b/GPIO_Test/GPIO_Test.uvprojx @@ -394,14 +394,9 @@ ..\Drivers\Sources\Driver_Timer.c - Driver_GPIO.h - 5 - ..\Drivers\Include\Driver_GPIO.h - - - Driver_Timer.h - 5 - ..\Drivers\Include\Driver_Timer.h + Driver_UART.c + 1 + ..\Drivers\Sources\Driver_UART.c @@ -811,14 +806,9 @@ ..\Drivers\Sources\Driver_Timer.c - Driver_GPIO.h - 5 - ..\Drivers\Include\Driver_GPIO.h - - - Driver_Timer.h - 5 - ..\Drivers\Include\Driver_Timer.h + Driver_UART.c + 1 + ..\Drivers\Sources\Driver_UART.c diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index 8d83a8c..912189b 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -1,5 +1,9 @@ #include "Driver_GPIO.h" #include "Driver_Timer.h" +#include "Driver_UART.h" + + char data = 'A'; + int cmp = 0; int main (void){ //Déclaration d'une LED et d'un BP par structure GPIO @@ -36,6 +40,16 @@ int main (void){ MyTimer_PWM(&TIM500ms, 50); + + UART_init(); + + while (cmp < 26) { + UART_send(data+cmp); + cmp ++; + } + + + while(1){ // if (MyGPIO_Read(BP.GPIO,BP.GPIO_Pin)==0){ // MyGPIO_Set(LED.GPIO,LED.GPIO_Pin); @@ -52,4 +66,4 @@ void TIM2_IRQHandler (void) MyGPIO_Toggle(GPIOA,5); TIM2->SR &= ~(1<<0); } -*/ \ No newline at end of file +*/ From e8800d0c58c2b2555f44a5b03f7cde9c91dda7e5 Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 27 Mar 2023 17:57:55 +0200 Subject: [PATCH 3/9] UART interrupt added --- Drivers/Include/Driver_UART.h | 4 +++- Drivers/Sources/Driver_UART.c | 24 ++++++++++++++++++++---- GPIO_Test/GPIO_Test.uvoptx | 24 ++++-------------------- GPIO_Test/Sources/Main.c | 23 +++++++++++++---------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Drivers/Include/Driver_UART.h b/Drivers/Include/Driver_UART.h index 77556d9..98e39a5 100644 --- a/Drivers/Include/Driver_UART.h +++ b/Drivers/Include/Driver_UART.h @@ -4,7 +4,9 @@ #include "stm32f10x.h" void UART_send(char data); -void UART_init(); +void UART_init(void); +void UART_ITHandler(void); + diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c index 396c0c8..2b1f6f9 100644 --- a/Drivers/Sources/Driver_UART.c +++ b/Drivers/Sources/Driver_UART.c @@ -1,16 +1,19 @@ #include "Driver_UART.h" -void UART_init() +void UART_init(void) { RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1 USART1->CR1 |= USART_CR1_UE; // Activer l'USART USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop - USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps + USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps partie entière USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire //USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600 - USART1->CR1 |= USART_CR1_TE; + USART1->CR1 |= USART_CR1_TE; // Autoriser la transmission + USART1->CR1 |= USART_CR1_RE; // Activer la réception + USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission + USART1->CR1 |= USART_CR1_RXNEIE; // Activer l'interruption de réception } void UART_send(char data) @@ -18,4 +21,17 @@ void UART_send(char data) USART1->DR |= data; while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission } - \ No newline at end of file + + +void UART_ITHandler(void) +{ + if (USART1->SR & USART_SR_RXNE) // si une donnée a été reçue + { + char received_data = USART1->DR; // lire la donnée reçue + } + + if (USART1->SR & USART_SR_TC) // si la transmission est terminée + { + USART1->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée + } +} diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index 66c8b4b..305a639 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=949,269,1397,683,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=-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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=930,345,1378,759,1)(161=1383,268,1831,682,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) 0 @@ -147,25 +147,9 @@ 0 0 - 47 + 51 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Sources\Main.c - - -
- - 1 - 0 - 47 - 1 -
134219276
+
134219346
0 0 0 @@ -174,7 +158,7 @@ 1 U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c - \\GPIO_Test\Sources/Main.c\47 + \\GPIO_Test\Sources/Main.c\51
diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index 912189b..333bc74 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -2,8 +2,9 @@ #include "Driver_Timer.h" #include "Driver_UART.h" - char data = 'A'; - int cmp = 0; + char data[] = "Hello World"; + int i = 0; + int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul int main (void){ //Déclaration d'une LED et d'un BP par structure GPIO @@ -40,14 +41,16 @@ int main (void){ MyTimer_PWM(&TIM500ms, 50); - - UART_init(); - - while (cmp < 26) { - UART_send(data+cmp); - cmp ++; - } - + + UART_init(); + + //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions + + // Envoyer les données + for (i = 0; i < len; i++) { + UART_send(data[i]); + } + while(1){ From f979a89e5fb7ead67c31360c7b277c99fe36ad4d Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 31 Mar 2023 12:21:52 +0200 Subject: [PATCH 4/9] UART Soon finish --- Drivers/Include/Driver_UART.h | 13 ++++++-- Drivers/Sources/Driver_UART.c | 61 ++++++++++++++++++++++++++++++---- GPIO_Test/GPIO_Test.uvoptx | 62 ++++++++++++++++++++++------------- GPIO_Test/Sources/Main.c | 13 +++++++- 4 files changed, 117 insertions(+), 32 deletions(-) diff --git a/Drivers/Include/Driver_UART.h b/Drivers/Include/Driver_UART.h index 98e39a5..c296384 100644 --- a/Drivers/Include/Driver_UART.h +++ b/Drivers/Include/Driver_UART.h @@ -3,9 +3,18 @@ #include "stm32f10x.h" +typedef struct { + USART_TypeDef * UART; + unsigned int baudrate; +}MyUART_Struct_Typedef; + void UART_send(char data); -void UART_init(void); -void UART_ITHandler(void); +char UART_read(char data, MyUART_Struct_Typedef * UART); +void UART_init(MyUART_Struct_Typedef * UART); +void USART1_IRQHandler(void); +void USART2_IRQHandler(void); +void USART3_IRQHandler(void); + diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c index 2b1f6f9..11ed828 100644 --- a/Drivers/Sources/Driver_UART.c +++ b/Drivers/Sources/Driver_UART.c @@ -1,15 +1,25 @@ #include "Driver_UART.h" -void UART_init(void) +char received_data1, received_data2, received_data3; + +void UART_init(MyUART_Struct_Typedef * UART) { + if(UART->UART ==USART1) + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; + if(UART->UART ==USART2) + RCC->APB2ENR |= RCC_APB1ENR_USART2EN; + if(UART->UART ==USART3) + RCC->APB2ENR |= RCC_APB1ENR_USART3EN; + + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1 USART1->CR1 |= USART_CR1_UE; // Activer l'USART USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop - USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps partie entière - USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire - //USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600 + //USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps partie entière + //USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire + UART->UART->BRR = 72000000/(UART->baudrate); USART1->CR1 |= USART_CR1_TE; // Autoriser la transmission USART1->CR1 |= USART_CR1_RE; // Activer la réception USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission @@ -18,16 +28,29 @@ void UART_init(void) void UART_send(char data) { + while(!(USART1->SR & USART_SR_TXE)){} //Attendre l'autorisation de transmission USART1->DR |= data; while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission } +char UART_read(char data, MyUART_Struct_Typedef * UART) + { + if(UART->UART == USART1) + return received_data1; + else if (UART->UART == USART2) + return received_data2; + else if (UART->UART == USART3) + return received_data3; + else + return 0; + } -void UART_ITHandler(void) + +void USART1_IRQHandler(void) { if (USART1->SR & USART_SR_RXNE) // si une donnée a été reçue { - char received_data = USART1->DR; // lire la donnée reçue + received_data1 = USART1->DR; // lire la donnée reçue } if (USART1->SR & USART_SR_TC) // si la transmission est terminée @@ -35,3 +58,29 @@ void UART_ITHandler(void) USART1->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée } } + +void USART2_IRQHandler(void) +{ + if (USART2->SR & USART_SR_RXNE) // si une donnée a été reçue + { + received_data2 = USART2->DR; // lire la donnée reçue + } + + if (USART2->SR & USART_SR_TC) // si la transmission est terminée + { + USART2->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée + } +} + +void USART3_IRQHandler(void) +{ + if (USART3->SR & USART_SR_RXNE) // si une donnée a été reçue + { + received_data3 = USART3->DR; // lire la donnée reçue + } + + if (USART3->SR & USART_SR_TC) // si la transmission est terminée + { + USART3->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée + } +} diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index 305a639..c3d2a1d 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -143,24 +143,7 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - - - 0 - 0 - 51 - 1 -
134219346
- 0 - 0 - 0 - 0 - 0 - 1 - U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c - - \\GPIO_Test\Sources/Main.c\51 -
-
+ 0 @@ -274,7 +257,7 @@ 1 0 - 0 + 1 18 @@ -347,14 +330,47 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - + + + 0 + 0 + 62 + 1 +
134218958
+ 0 + 0 + 0 + 0 + 0 + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c + + \\GPIO_Test\Sources/Main.c\62 +
+ + 1 + 0 + 53 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Sources\Main.c + + +
+
0 0 1 - 1 + 0 0 0 0 @@ -422,7 +438,7 @@ 1 2 1 - 0 + 1 0 0 ..\Drivers\Sources\Driver_Timer.c diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index 333bc74..e67bed9 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -10,8 +10,15 @@ 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 MyTimer_Struct_TypeDef TIM500ms; + + //Déclaration de l'UART + MyUART_Struct_Typedef * UART; + UART->UART=USART1; + UART->baudrate=9600; + //Config LED PA5 LED.GPIO_Conf = Out_Ppull; LED.GPIO_Pin = 5; @@ -42,7 +49,8 @@ int main (void){ MyTimer_PWM(&TIM500ms, 50); - UART_init(); + + UART_init(UART); //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions @@ -50,6 +58,9 @@ int main (void){ for (i = 0; i < len; i++) { UART_send(data[i]); } + + UART_read(data[i], UART); + From 582dd2b5b769de61f9019e87b280c708381e6a67 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 4 Apr 2023 14:53:57 +0200 Subject: [PATCH 5/9] UART done --- Drivers/Include/Driver_GPIO.h | 1 + Drivers/Sources/Driver_GPIO.c | 63 +++++++++++------- Drivers/Sources/Driver_UART.c | 33 ++++++++-- GPIO_Test/GPIO_Test.uvoptx | 120 +++++++++++++++++++++------------- GPIO_Test/Sources/Main.c | 31 ++++++--- 5 files changed, 164 insertions(+), 84 deletions(-) diff --git a/Drivers/Include/Driver_GPIO.h b/Drivers/Include/Driver_GPIO.h index 10cc25c..4109e4d 100644 --- a/Drivers/Include/Driver_GPIO.h +++ b/Drivers/Include/Driver_GPIO.h @@ -23,4 +23,5 @@ int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; // renvoie 0 ou autre void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; + #endif diff --git a/Drivers/Sources/Driver_GPIO.c b/Drivers/Sources/Driver_GPIO.c index 695d4a7..bac8120 100644 --- a/Drivers/Sources/Driver_GPIO.c +++ b/Drivers/Sources/Driver_GPIO.c @@ -2,35 +2,47 @@ //---------------------FONCTION D'INITIALISATION-----------------// -void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr){ +void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) +{ -//INITIALISATION DE LA CLOCK CORRESPONDANT AU GPIO A, B ou C - if (GPIOStructPtr->GPIO == GPIOA) { - 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; + /* Activation of the GPIO port specific clock */ + if (GPIOStructPtr->GPIO == GPIOA) + { + 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 */ + if(GPIOStructPtr->GPIO_Pin <= 8) + { + GPIOStructPtr->GPIO->CRL &= ~0xF<<(4*(GPIOStructPtr->GPIO_Pin)); + GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf)<<(4*(GPIOStructPtr->GPIO_Pin)); + } + else + { + GPIOStructPtr->GPIO->CRH &= ~0xF<<(4*((GPIOStructPtr->GPIO_Pin)%8)); + GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf)<<(4*((GPIOStructPtr->GPIO_Pin)%8)); } -//CONFIGURATION DE LA PIN UTILISEE (voir table20 p9.1) - if(GPIOStructPtr->GPIO_Pin < 8){ - GPIOStructPtr->GPIO->CRL &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin)); - GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf << (4 * GPIOStructPtr->GPIO_Pin)); + if(GPIOStructPtr->GPIO_Conf == (char)In_PullDown) + { + GPIOStructPtr->GPIO->ODR &= ~(0x1<<(GPIOStructPtr->GPIO_Pin)); } - else { - GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin - 8)); - GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf << (4 * GPIOStructPtr->GPIO_Pin - 8)); - } - -//CONFIGURATION DE L'ODR EN ENTREE (pull up et down uniquement) - if(GPIOStructPtr->GPIO_Conf == In_PullUp){ - GPIOStructPtr->GPIO->ODR = 0x1; - } - else if(GPIOStructPtr->GPIO_Conf == In_PullDown){ - GPIOStructPtr->GPIO->ODR = 0x0; + else if(GPIOStructPtr->GPIO_Conf == (char)In_PullUp) + { + GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin); } } @@ -62,3 +74,4 @@ void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ){ void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ){ GPIO->ODR ^= (1 << GPIO_Pin); } + diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c index 11ed828..b76c540 100644 --- a/Drivers/Sources/Driver_UART.c +++ b/Drivers/Sources/Driver_UART.c @@ -7,10 +7,10 @@ void UART_init(MyUART_Struct_Typedef * UART) { if(UART->UART ==USART1) RCC->APB2ENR |= RCC_APB2ENR_USART1EN; - if(UART->UART ==USART2) - RCC->APB2ENR |= RCC_APB1ENR_USART2EN; - if(UART->UART ==USART3) - RCC->APB2ENR |= RCC_APB1ENR_USART3EN; + else if(UART->UART ==USART2) + RCC->APB1ENR |= RCC_APB1ENR_USART2EN; + else if(UART->UART ==USART3) + RCC->APB1ENR |= RCC_APB1ENR_USART3EN; RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1 @@ -28,9 +28,9 @@ void UART_init(MyUART_Struct_Typedef * UART) void UART_send(char data) { - while(!(USART1->SR & USART_SR_TXE)){} //Attendre l'autorisation de transmission + while(!(USART1->SR & USART_SR_TXE) | !(USART2->SR & USART_SR_TXE)){} //Attendre l'autorisation de transmission USART1->DR |= data; - while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission + while(!(USART1->SR & USART_SR_TC) | !(USART2->SR & USART_SR_TC)){} //Attendre la fin de transmission } char UART_read(char data, MyUART_Struct_Typedef * UART) @@ -84,3 +84,24 @@ void USART3_IRQHandler(void) USART3->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée } } + + +void UART_interruption (MyUART_Struct_Typedef * UART) +{ + UART->UART->CR1 |= USART_CR1_RXNEIE; + + if (UART->UART==USART1) + { + NVIC->ISER[1] |= (1<<(USART1_IRQn-32)); + } + if (UART->UART==USART2) + { + NVIC->ISER[1] |= (1<<(USART2_IRQn-32)); + } + if (UART->UART==USART3) + { + NVIC->ISER[1] |= (1<<(USART3_IRQn-32)); + } + +} + diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index c3d2a1d..4548a0d 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.uvoptx @@ -75,7 +75,7 @@ 1 0 - 0 + 1 18 @@ -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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=930,345,1378,759,1)(161=1383,268,1831,682,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=-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=865,485,1286,912,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1131,175,1579,589,1)(161=1383,268,1831,682,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) 0 @@ -143,7 +143,72 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - + + + 0 + 0 + 30 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Sources\Main.c + + +
+ + 1 + 0 + 30 + 1 +
134219668
+ 0 + 0 + 0 + 0 + 0 + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c + + \\GPIO_Test\Sources/Main.c\30 +
+ + 2 + 0 + 70 + 1 +
134219784
+ 0 + 0 + 0 + 0 + 0 + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c + + \\GPIO_Test\Sources/Main.c\70 +
+ + 3 + 0 + 71 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Sources\Main.c + + +
+
0 @@ -152,7 +217,7 @@ 1 0 0 - 0 + 1 0 0 1 @@ -257,7 +322,7 @@ 1 0 - 1 + 0 18 @@ -330,40 +395,7 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - - - 0 - 0 - 62 - 1 -
134218958
- 0 - 0 - 0 - 0 - 0 - 1 - U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c - - \\GPIO_Test\Sources/Main.c\62 -
- - 1 - 0 - 53 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\Sources\Main.c - - -
-
+ 0 @@ -372,7 +404,7 @@ 1 0 0 - 0 + 1 0 0 1 @@ -426,7 +458,7 @@ 1 1 1 - 0 + 1 0 0 ..\Drivers\Sources\Driver_GPIO.c @@ -438,7 +470,7 @@ 1 2 1 - 1 + 0 0 0 ..\Drivers\Sources\Driver_Timer.c @@ -450,7 +482,7 @@ 1 3 1 - 1 + 0 0 0 ..\Drivers\Sources\Driver_UART.c @@ -470,7 +502,7 @@ 2 4 1 - 1 + 0 0 0 .\Sources\Main.c diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index e67bed9..f0d3c98 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -2,9 +2,9 @@ #include "Driver_Timer.h" #include "Driver_UART.h" - char data[] = "Hello World"; - int i = 0; - int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul +char data[] = "Hello World"; +int i = 0; +int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul int main (void){ //Déclaration d'une LED et d'un BP par structure GPIO @@ -14,10 +14,22 @@ int main (void){ //Déclaration d'un Timer 500 ms MyTimer_Struct_TypeDef TIM500ms; - //Déclaration de l'UART - MyUART_Struct_Typedef * UART; - UART->UART=USART1; - UART->baudrate=9600; + //Déclaration de l'UART / + MyUART_Struct_Typedef UART1 = {USART1,9600}; + MyUART_Struct_Typedef UART2 = {USART2,9600}; + + //UART2 + //MyGPIO_Struct_TypeDef PA2 = {GPIOA,2,AltOut_Ppull}; + //MyGPIO_Struct_TypeDef PA3 = {GPIOA,3,In_PullUp}; + //UART1 + MyGPIO_Struct_TypeDef PA9 = {GPIOA,9,AltOut_Ppull}; + MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,In_Floating}; + + + //MyGPIO_Init (&PA2); + //MyGPIO_Init (&PA3); + MyGPIO_Init (&PA9); + MyGPIO_Init (&PA10); //Config LED PA5 LED.GPIO_Conf = Out_Ppull; @@ -50,7 +62,8 @@ int main (void){ - UART_init(UART); + UART_init(&UART1); + UART_init(&UART2); //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions @@ -59,7 +72,7 @@ int main (void){ UART_send(data[i]); } - UART_read(data[i], UART); + UART_read(data[i], &UART1); From a9d0437841c71da0fd00e8c5643137f103193b7f Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 4 Apr 2023 15:17:52 +0200 Subject: [PATCH 6/9] UART : GPIO selection add --- Drivers/Include/Driver_UART.h | 3 +- Drivers/Sources/Driver_UART.c | 37 ++++++++++++++- GPIO_Test/GPIO_Test.uvoptx | 84 +++++++++++++++++------------------ GPIO_Test/Sources/Main.c | 27 +++-------- 4 files changed, 85 insertions(+), 66 deletions(-) diff --git a/Drivers/Include/Driver_UART.h b/Drivers/Include/Driver_UART.h index c296384..fc9e08a 100644 --- a/Drivers/Include/Driver_UART.h +++ b/Drivers/Include/Driver_UART.h @@ -14,8 +14,7 @@ void UART_init(MyUART_Struct_Typedef * UART); void USART1_IRQHandler(void); void USART2_IRQHandler(void); void USART3_IRQHandler(void); - - +void UART_InitGPIO(MyUART_Struct_Typedef * UART); diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c index b76c540..3d98d55 100644 --- a/Drivers/Sources/Driver_UART.c +++ b/Drivers/Sources/Driver_UART.c @@ -1,4 +1,5 @@ #include "Driver_UART.h" +#include "Driver_GPIO.h" char received_data1, received_data2, received_data3; @@ -102,6 +103,40 @@ void UART_interruption (MyUART_Struct_Typedef * UART) { NVIC->ISER[1] |= (1<<(USART3_IRQn-32)); } - } +void UART_InitGPIO(MyUART_Struct_Typedef * UART) +{ + if(UART->UART == USART1) + { + MyUART_Struct_Typedef UART1 = {USART1,9600}; + MyGPIO_Struct_TypeDef PA9 = {GPIOA,9,AltOut_Ppull}; + MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,In_PullUp}; + MyGPIO_Init (&PA9); + MyGPIO_Init (&PA10); + UART_init(&UART1); + } + else if(UART->UART == USART2) { + MyUART_Struct_Typedef UART2 = {USART2,9600}; + MyGPIO_Struct_TypeDef PA2 = {GPIOA,2,AltOut_Ppull}; + MyGPIO_Struct_TypeDef PA3 = {GPIOA,3,In_Floating}; + MyGPIO_Init (&PA2); + MyGPIO_Init (&PA3); + UART_init(&UART2); + } + else if(UART->UART == USART3) { + MyUART_Struct_Typedef UART3 = {USART3,9600}; + MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,AltOut_Ppull}; + MyGPIO_Struct_TypeDef PA11 = {GPIOA,11,In_PullUp}; + MyGPIO_Init (&PA10); + MyGPIO_Init (&PA11); + UART_init(&UART3); + } + else { + return; + } + +} + + + diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index 4548a0d..6dd6ca4 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.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=865,485,1286,912,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1131,175,1579,589,1)(161=1383,268,1831,682,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=-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=1357,482,1778,909,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1345,64,1793,478,1)(161=1383,268,1831,682,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) 0 @@ -147,56 +147,24 @@ 0 0 - 30 - 1 -
0
+ 38 + 0 +
134219492
0 0 0 0 0 - 0 - .\Sources\Main.c + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\Drivers\Sources\Driver_UART.c - + \\GPIO_Test\../Drivers/Sources/Driver_UART.c\38
1 0 - 30 - 1 -
134219668
- 0 - 0 - 0 - 0 - 0 - 1 - U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c - - \\GPIO_Test\Sources/Main.c\30 -
- - 2 - 0 - 70 - 1 -
134219784
- 0 - 0 - 0 - 0 - 0 - 1 - U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c - - \\GPIO_Test\Sources/Main.c\70 -
- - 3 - 0 - 71 - 1 + 39 + 0
0
0 0 @@ -204,7 +172,39 @@ 0 0 0 - .\Sources\Main.c + ..\Drivers\Sources\Driver_UART.c + + +
+ + 2 + 0 + 54 + 0 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + ..\Drivers\Sources\Driver_UART.c + + +
+ + 3 + 0 + 67 + 0 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + ..\Drivers\Sources\Driver_UART.c
diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index f0d3c98..8c2d4ba 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -10,26 +10,10 @@ int main (void){ //Déclaration d'une LED et d'un BP par structure GPIO MyGPIO_Struct_TypeDef LED; MyGPIO_Struct_TypeDef BP; - + MyUART_Struct_Typedef UART; //Déclaration d'un Timer 500 ms MyTimer_Struct_TypeDef TIM500ms; - //Déclaration de l'UART / - MyUART_Struct_Typedef UART1 = {USART1,9600}; - MyUART_Struct_Typedef UART2 = {USART2,9600}; - - //UART2 - //MyGPIO_Struct_TypeDef PA2 = {GPIOA,2,AltOut_Ppull}; - //MyGPIO_Struct_TypeDef PA3 = {GPIOA,3,In_PullUp}; - //UART1 - MyGPIO_Struct_TypeDef PA9 = {GPIOA,9,AltOut_Ppull}; - MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,In_Floating}; - - - //MyGPIO_Init (&PA2); - //MyGPIO_Init (&PA3); - MyGPIO_Init (&PA9); - MyGPIO_Init (&PA10); //Config LED PA5 LED.GPIO_Conf = Out_Ppull; @@ -49,6 +33,9 @@ int main (void){ TIM500ms.ARR = 5000; MyTimer_Base_Init(&TIM500ms); + //InitUART + UART.UART = USART1; + /* TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH //TIM2->DIER |= TIM_DIER_UIE ; @@ -62,17 +49,15 @@ int main (void){ - UART_init(&UART1); - UART_init(&UART2); //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions - + UART_InitGPIO(&UART); // Envoyer les données for (i = 0; i < len; i++) { UART_send(data[i]); } - UART_read(data[i], &UART1); + UART_read(data[i], &UART); From 30ceea84e7967e8a1a7876ff71027519a0308d5b Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 7 Apr 2023 13:30:06 +0200 Subject: [PATCH 7/9] UART DONE --- Drivers/Include/Driver_UART.h | 1 + Drivers/Sources/Driver_UART.c | 6 ++- GPIO_Test/GPIO_Test.uvoptx | 73 ++--------------------------------- 3 files changed, 9 insertions(+), 71 deletions(-) diff --git a/Drivers/Include/Driver_UART.h b/Drivers/Include/Driver_UART.h index fc9e08a..23134ad 100644 --- a/Drivers/Include/Driver_UART.h +++ b/Drivers/Include/Driver_UART.h @@ -15,6 +15,7 @@ void USART1_IRQHandler(void); void USART2_IRQHandler(void); void USART3_IRQHandler(void); void UART_InitGPIO(MyUART_Struct_Typedef * UART); +void UART_interruption (MyUART_Struct_Typedef * UART); diff --git a/Drivers/Sources/Driver_UART.c b/Drivers/Sources/Driver_UART.c index 3d98d55..87bcfd3 100644 --- a/Drivers/Sources/Driver_UART.c +++ b/Drivers/Sources/Driver_UART.c @@ -23,8 +23,10 @@ void UART_init(MyUART_Struct_Typedef * UART) UART->UART->BRR = 72000000/(UART->baudrate); USART1->CR1 |= USART_CR1_TE; // Autoriser la transmission USART1->CR1 |= USART_CR1_RE; // Activer la réception - USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission + // USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission USART1->CR1 |= USART_CR1_RXNEIE; // Activer l'interruption de réception + UART_interruption(UART); + } void UART_send(char data) @@ -46,7 +48,7 @@ char UART_read(char data, MyUART_Struct_Typedef * UART) return 0; } - + void USART1_IRQHandler(void) { if (USART1->SR & USART_SR_RXNE) // si une donnée a été reçue diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index 6dd6ca4..c7434e3 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.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=1357,482,1778,909,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1345,64,1793,478,1)(161=1383,268,1831,682,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=75,104,451,661,1)(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=1357,482,1778,909,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=798,177,1246,591,1)(161=1383,268,1831,682,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) 0 @@ -143,72 +143,7 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - - - 0 - 0 - 38 - 0 -
134219492
- 0 - 0 - 0 - 0 - 0 - 1 - U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\Drivers\Sources\Driver_UART.c - - \\GPIO_Test\../Drivers/Sources/Driver_UART.c\38 -
- - 1 - 0 - 39 - 0 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - ..\Drivers\Sources\Driver_UART.c - - -
- - 2 - 0 - 54 - 0 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - ..\Drivers\Sources\Driver_UART.c - - -
- - 3 - 0 - 67 - 0 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - ..\Drivers\Sources\Driver_UART.c - - -
-
+ 0 @@ -458,7 +393,7 @@ 1 1 1 - 1 + 0 0 0 ..\Drivers\Sources\Driver_GPIO.c @@ -482,7 +417,7 @@ 1 3 1 - 0 + 1 0 0 ..\Drivers\Sources\Driver_UART.c From 7f879cf7afe351af00512d2769e2b0b20ea32e44 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 7 Apr 2023 13:46:35 +0200 Subject: [PATCH 8/9] ADC +UART --- Drivers/Include/Driver_ADC.h | 21 ++++++++++++++++++++ GPIO_Test/GPIO_Test.uvoptx | 37 ++++++++++++++++++++++++++++++++---- GPIO_Test/GPIO_Test.uvprojx | 10 ++++++++++ GPIO_Test/Sources/Main.c | 37 +++++++++++++++++++++++++----------- 4 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 Drivers/Include/Driver_ADC.h diff --git a/Drivers/Include/Driver_ADC.h b/Drivers/Include/Driver_ADC.h new file mode 100644 index 0000000..2218bc9 --- /dev/null +++ b/Drivers/Include/Driver_ADC.h @@ -0,0 +1,21 @@ +#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); +void MyADC_Base_Interuption(ADC_TypeDef * ADC); +int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC); +void MyADC_Init_Periph (void (*fct)(void)); + +#endif diff --git a/GPIO_Test/GPIO_Test.uvoptx b/GPIO_Test/GPIO_Test.uvoptx index c7434e3..cb2cfa2 100644 --- a/GPIO_Test/GPIO_Test.uvoptx +++ b/GPIO_Test/GPIO_Test.uvoptx @@ -125,7 +125,7 @@ 0 DLGDARM - (1010=75,104,451,661,1)(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=1357,482,1778,909,1)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=798,177,1246,591,1)(161=1383,268,1831,682,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=937,133,1313,690,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=1357,482,1778,909,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1375,56,1823,470,0)(161=1383,268,1831,682,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=240,283,843,1034,0)(151=-1,-1,-1,-1,0) 0 @@ -143,7 +143,24 @@ -U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - + + + 0 + 0 + 69 + 1 +
134219582
+ 0 + 0 + 0 + 0 + 0 + 1 + U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c + + \\GPIO_Test\Sources/Main.c\69 +
+
0 @@ -417,7 +434,7 @@ 1 3 1 - 1 + 0 0 0 ..\Drivers\Sources\Driver_UART.c @@ -425,6 +442,18 @@ 0 0 + + 1 + 4 + 1 + 1 + 0 + 0 + C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c + Driver_ADC.c + 0 + 0 + @@ -435,7 +464,7 @@ 0 2 - 4 + 5 1 0 0 diff --git a/GPIO_Test/GPIO_Test.uvprojx b/GPIO_Test/GPIO_Test.uvprojx index 1c6256e..61c2421 100644 --- a/GPIO_Test/GPIO_Test.uvprojx +++ b/GPIO_Test/GPIO_Test.uvprojx @@ -398,6 +398,11 @@ 1 ..\Drivers\Sources\Driver_UART.c + + Driver_ADC.c + 1 + C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c + @@ -810,6 +815,11 @@ 1 ..\Drivers\Sources\Driver_UART.c + + Driver_ADC.c + 1 + C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c + diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index 8c2d4ba..6f6cfe6 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -1,10 +1,13 @@ #include "Driver_GPIO.h" #include "Driver_Timer.h" #include "Driver_UART.h" +#include "Driver_ADC.h" + char data[] = "Hello World"; int i = 0; int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul +void ADC_interrup(void); int main (void){ //Déclaration d'une LED et d'un BP par structure GPIO @@ -14,7 +17,8 @@ int main (void){ //Déclaration d'un Timer 500 ms MyTimer_Struct_TypeDef TIM500ms; - + //Déclaration ADC de Test + MyADC_Struct_TypeDef ADCTEST; //Config LED PA5 LED.GPIO_Conf = Out_Ppull; LED.GPIO_Pin = 5; @@ -49,7 +53,7 @@ int main (void){ - + /* //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions UART_InitGPIO(&UART); // Envoyer les données @@ -57,18 +61,19 @@ int main (void){ UART_send(data[i]); } - UART_read(data[i], &UART); - + //UART_read(data[i], &UART); +*/ - + //ADC + //TEST ADC// + ADCTEST.ADC = ADC1; + ADCTEST.Channel = 0; + MyADC_Base_Init(&ADCTEST); + MyADC_Base_Interuption(ADCTEST.ADC); + MyADC_Init_Periph(ADC_interrup); 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); -// } - + MyADC_Base_Start(ADCTEST.ADC); } } @@ -79,3 +84,13 @@ void TIM2_IRQHandler (void) TIM2->SR &= ~(1<<0); } */ +void Timer_interup(void) +{ + MyGPIO_Toggle(GPIOA,5); +} + +//Interruption du programme par trigger de l'ADC +void ADC_interrup() +{ + +} From 7930acf1ef19a626fc1d7220ff9b6eff949111ab Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 7 Apr 2023 13:57:29 +0200 Subject: [PATCH 9/9] UART + ADC --- GPIO_Test/Sources/Main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPIO_Test/Sources/Main.c b/GPIO_Test/Sources/Main.c index 6f6cfe6..41b0a4e 100644 --- a/GPIO_Test/Sources/Main.c +++ b/GPIO_Test/Sources/Main.c @@ -53,7 +53,7 @@ int main (void){ - /* + //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions UART_InitGPIO(&UART); // Envoyer les données @@ -62,7 +62,7 @@ int main (void){ } //UART_read(data[i], &UART); -*/ + //ADC //TEST ADC//