diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 7329a62..1aede9a 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -460,7 +460,7 @@ 2 2 1 - 1 + 0 0 0 ..\Services\MyRF.c @@ -480,7 +480,7 @@ 3 3 1 - 1 + 0 0 0 ..\MyDrivers\MyTimer.c @@ -492,7 +492,7 @@ 3 4 1 - 1 + 0 0 0 ..\MyDrivers\MyPWM.c @@ -500,6 +500,18 @@ 0 0 + + 3 + 5 + 1 + 0 + 0 + 0 + ..\MyDrivers\MyUSART.c + MyUSART.c + 0 + 0 + @@ -510,7 +522,7 @@ 0 4 - 5 + 6 1 0 0 @@ -522,7 +534,7 @@ 4 - 6 + 7 1 0 0 @@ -534,7 +546,7 @@ 4 - 7 + 8 1 0 0 @@ -546,7 +558,7 @@ 4 - 8 + 9 1 0 0 @@ -558,7 +570,7 @@ 4 - 9 + 10 1 0 0 @@ -578,7 +590,7 @@ 0 5 - 10 + 11 5 0 0 @@ -598,7 +610,7 @@ 0 6 - 11 + 12 1 0 0 @@ -618,7 +630,7 @@ 0 7 - 12 + 13 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index 0d68036..ba1fe3c 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -412,6 +412,11 @@ 1 ..\MyDrivers\MyPWM.c + + MyUSART.c + 1 + ..\MyDrivers\MyUSART.c + @@ -885,6 +890,11 @@ 1 ..\MyDrivers\MyPWM.c + + MyUSART.c + 1 + ..\MyDrivers\MyUSART.c + diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index 1905014..1cb3719 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -1,5 +1,5 @@ -#ifndef PWM_H -#define PWM_H +#ifndef MYPWM_H +#define MYPWM_H #include "stm32f103xb.h" diff --git a/Services/MyRF.c b/Services/MyRF.c index 4e40930..92c474d 100644 --- a/Services/MyRF.c +++ b/Services/MyRF.c @@ -1,34 +1,58 @@ #include "MyRF.h" #include "MyTimer.h" #include "MyPWM.h" +#include "MyUSART.h" #include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges #include "stm32f1xx_ll_tim.h" #include "stm32f1xx_ll_gpio.h" +#include "stm32f1xx_ll_usart.h" void MyRF_Conf(void) { - //Initialisation du GPIO + //RX + //Activation horloge du GPIO LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); LL_GPIO_InitTypeDef My_GPIO_Init_Struct; - LL_GPIO_StructInit(&My_GPIO_Init_Struct); //PB.6 en floating input My_GPIO_Init_Struct.Pin = PinCH1; - LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct); //PB.7 en floating input My_GPIO_Init_Struct.Pin = PinCH2; - LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct); + + //Configuration et lancment du Timer PWM Input MyTimer_Conf(TimerCC,0xFFAD,0x15); - MyPWM_Conf_Input(TimerCC, channelCC1, channelCC2); - MyTimer_Start(TimerCC); + + //TX + //Activation horloge du GPIO + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); + + LL_GPIO_StructInit(&My_GPIO_Init_Struct); + + //PA.9 en alternate output pp + My_GPIO_Init_Struct.Pin = PinOut; + My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; + My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + LL_GPIO_Init(GPIOOut, &My_GPIO_Init_Struct); + + //Configuration de l'USART + MyUSART_Conf(USARTOut, TransferDirTX); + + //Configuration Timer (interruption à 3s, callback MyRF_Transmit_3s) et lancement + MyTimer_Conf(TimerRF,65633,3290); + MyTimer_IT_Conf(TimerRF,MyRF_Transmit_3s,3); + MyTimer_IT_Enable(TimerRF); + MyTimer_Start(TimerRF); + } int MyRF_Input_Duty_Cycle(void) { @@ -36,3 +60,72 @@ int MyRF_Input_Duty_Cycle(void) { return (MyPWM_Duty_Cycle_Permilles(TimerCC, channelCC1, channelCC2) - 75) * 4; } + +void MyRF_Transmit_3s(void) { + + //Récupérer : + char bordage[3]; + char heure[2]; + char min[2]; + char sec[2]; + int allure_ref = 0; + + char allure[7][30] = {"pas (ou vent debout).", + "au plus près.", + "au près.", + "au bon plein.", + "au travers.", + "au grand largue.", + "au vent arrière." + }; + char data1[23] = "\" : le voilier navigue "; + char data2[15] = " === Bordage : "; + + int i; + + //Heure + MyUSART_Transmit_Data_8b(USARTOut, heure[0]); + MyUSART_Transmit_Data_8b(USARTOut, heure[1]); + MyUSART_Transmit_Data_8b(USARTOut, 'h'); + //Minutes + MyUSART_Transmit_Data_8b(USARTOut, min[0]); + MyUSART_Transmit_Data_8b(USARTOut, min[1]); + MyUSART_Transmit_Data_8b(USARTOut, '\''); + //Secondes + MyUSART_Transmit_Data_8b(USARTOut, sec[0]); + MyUSART_Transmit_Data_8b(USARTOut, sec[1]); + //Texte 1 (allures) + for(i=0; i<23; i++) { + MyUSART_Transmit_Data_8b(USARTOut, data1[i]); + } + //Allure + for(i=0; i<30; i++) { + MyUSART_Transmit_Data_8b(USARTOut, allure[allure_ref][i]); + } + //Texte 2 (bordage) + for(i=0; i<15; i++) { + MyUSART_Transmit_Data_8b(USARTOut, data2[i]); + } + //Bordage + for(i=0; i<3; i++) { + MyUSART_Transmit_Data_8b(USARTOut, bordage[i]); + } + MyUSART_Transmit_Data_8b(USARTOut, '%'); + //Newline (fin) + MyUSART_Transmit_Data_8b(USARTOut, '\n'); + +} + +void MyRF_Transmit_Batterie_Faible(void) { + char data[24] = "/!\\ BATTERIE FAIBLE /!\\\n"; + for(int i = 0; i<24; i++) { + MyUSART_Transmit_Data_8b(USARTOut, data[i]); + } +} + +void MyRF_Transmit_Limite_Roulis(void) { + char data[30] = "/!\\ RISQUE DE CHAVIREMENT /!\\\n"; + for(int i = 0; i<30; i++) { + MyUSART_Transmit_Data_8b(USARTOut, data[i]); + } +} diff --git a/Services/MyRF.h b/Services/MyRF.h index 4670582..98b5cef 100644 --- a/Services/MyRF.h +++ b/Services/MyRF.h @@ -5,14 +5,26 @@ #define PinCH1 LL_GPIO_PIN_6 #define PinCH2 LL_GPIO_PIN_7 -#define GPIOPins GPIOB +#define PinOut LL_GPIO_PIN_9 +#define PinTXEn LL_GPIO_PIN_11 +#define GPIOIn GPIOB +#define GPIOOut GPIOA #define TimerCC TIM4 #define channelCC1 LL_TIM_CHANNEL_CH1 #define channelCC2 LL_TIM_CHANNEL_CH2 +#define USARTOut USART1 +#define TransferDirTX LL_USART_DIRECTION_TX +#define TimerRF TIM1 void MyRF_Conf(void); int MyRF_Duty_Cycle_Moteur(void); +void MyRF_Transmit_3s(void); + +void MyRF_Transmit_Batterie_Faible(void); + +void MyRF_Transmit_Limite_Roulis(void); + #endif