Voilier/GPIO_Test/Sources/Main.c
2023-04-04 14:53:57 +02:00

96 lines
2 KiB
C

#include "Driver_GPIO.h"
#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
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 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;
LED.GPIO_Pin = 5;
LED.GPIO = GPIOA;
MyGPIO_Init (&LED) ;
//Config BP PC13
BP.GPIO_Conf = In_Floating;
BP.GPIO_Pin = 13;
BP.GPIO = GPIOC;
//Init BP & LED
MyGPIO_Init (&LED);
MyGPIO_Init (&BP);
//Init Timer 2 et Test
TIM500ms.Timer = TIM2;
TIM500ms.PSC = 7200; // =0.5ms(calculé à partir de la fréquence du micro)
TIM500ms.ARR = 5000;
MyTimer_Base_Init(&TIM500ms);
/*
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
//TIM2->DIER |= TIM_DIER_UIE ;
NVIC->ISER[0] |= 1<<TIM2_IRQn ; //INTERRUPTION COEUR
NVIC->IP[TIM2_IRQn] = 2<< 4 ;
*/
MyTimer_Base_Start(TIM500ms.Timer);
//Boucle infinie de la réponse de la LED à l'état BP
MyTimer_PWM(&TIM500ms, 50);
UART_init(&UART1);
UART_init(&UART2);
//NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions
// Envoyer les données
for (i = 0; i < len; i++) {
UART_send(data[i]);
}
UART_read(data[i], &UART1);
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);
// }
}
}
/*
void TIM2_IRQHandler (void)
{
MyGPIO_Toggle(GPIOA,5);
TIM2->SR &= ~(1<<0);
}
*/