diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index 842febe..0087522 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -153,40 +153,7 @@
-U-O142 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)
-
-
- 0
- 0
- 44
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- ../Src/main.c
-
-
-
-
- 1
- 0
- 47
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- ../Src/main.c
-
-
-
-
+
0
@@ -208,7 +175,7 @@
1
0
0
- 0
+ 1
0
1
0
@@ -350,7 +317,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=-1,-1,-1,-1,0)(121=-1,-1,-1,-1,0)(122=908,72,1329,499,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=-1,-1,-1,-1,0)(132=854,46,1448,797,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=-1,-1,-1,-1,0)(121=-1,-1,-1,-1,0)(122=908,72,1329,499,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=-1,-1,-1,-1,0)(132=854,46,1448,797,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=990,76,1438,490,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
@@ -387,6 +354,38 @@
0
0
+ 139
+ 1
+ 134218202
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ..\Services\Chrono.c
+
+ \\NUCLEO_F103RB\../Services/Chrono.c\139
+
+
+ 1
+ 0
+ 82
+ 1
+ 134218440
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ..\Services\Chrono.c
+
+ \\NUCLEO_F103RB\../Services/Chrono.c\82
+
+
+ 2
+ 0
153
1
134217996
@@ -401,7 +400,7 @@
\\NUCLEO_F103RB\startup_stm32f103xb.s\153
- 1
+ 3
0
143
1
@@ -417,11 +416,11 @@
\\NUCLEO_F103RB\startup_stm32f103xb.s\143
- 2
+ 4
0
46
1
- 134219942
+ 134221228
0
0
0
@@ -454,7 +453,7 @@
1
0
0
- 0
+ 1
0
1
0
@@ -611,6 +610,18 @@
0
0
+
+ 4
+ 8
+ 1
+ 0
+ 0
+ 0
+ ..\LLDrivers\src\stm32f1xx_ll_usart.c
+ stm32f1xx_ll_usart.c
+ 0
+ 0
+
@@ -621,7 +632,7 @@
0
5
- 8
+ 9
5
0
0
@@ -641,7 +652,7 @@
0
6
- 9
+ 10
1
0
0
@@ -661,7 +672,7 @@
0
7
- 10
+ 11
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index faf19d8..eef1086 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -432,6 +432,11 @@
1
..\LLDrivers\src\stm32f1xx_ll_gpio.c
+
+ stm32f1xx_ll_usart.c
+ 1
+ ..\LLDrivers\src\stm32f1xx_ll_usart.c
+
@@ -895,6 +900,11 @@
1
..\LLDrivers\src\stm32f1xx_ll_gpio.c
+
+ stm32f1xx_ll_usart.c
+ 1
+ ..\LLDrivers\src\stm32f1xx_ll_usart.c
+
diff --git a/Services/Chrono.c b/Services/Chrono.c
index 137e6b5..bf6b429 100644
--- a/Services/Chrono.c
+++ b/Services/Chrono.c
@@ -6,13 +6,17 @@ Utilise un timer au choix (TIMER1
Utilise la lib MyTimers.h /.c
*/
+/* GSM -> SMS
+driver*/
-#include "Chrono.h"
-#include "MyTimer.h"
-#include "stm32f1xx_ll_gpio.h"
+#include "Chrono.h" //header du chrono
+#include "MyTimer.h" //header du timer
+#include "stm32f1xx_ll_gpio.h" // GPIO
#include "stm32f1xx_ll_bus.h" // CLock
-#include "stm32f1xx_ll_utils.h"
+#include "stm32f1xx_ll_utils.h" //Pour la fonction mDelay
+#include "stm32f1xx_ll_usart.h" //USART
+#define TAILLE_MESSAGE 9 //Taille de chaques messages envoyé (xx:xx:xx: => 9 digits)
// variable privée de type Time qui mémorise la durée mesurée
static Time Chrono_Time; // rem : static rend la visibilité de la variable Chrono_Time limitée à ce fichier
@@ -20,9 +24,72 @@ static Time Chrono_Time; // rem : static rend la visibilit
// variable privée qui mémorise pour le module le timer utilisé par le module
static TIM_TypeDef * Chrono_Timer=TIM1; // init par défaut au cas où l'utilisateur ne lance pas Chrono_Conf avant toute autre fct.
+// Variable globale qui sert de drapeau de communication entre le BG et chronoTask10ms (et reset)
+static char drapeau = 0;
+
+// Structure pour gérer la transmission du message
+struct t_transmission {
+ char message[TAILLE_MESSAGE];// Le message lui même
+ char end_of_message;// le caractère de fin (Retour Chariot)
+ int position;// La position du caractere a envoyer
+ char first_appel;// Booléen sur le premier appel (si true, lire l'heure et construire le message)
+};
+
+/**
+ * @brief Initialise une structure t_transmission.
+ * @note Structure initialisée : (message -> 00:00:00:, end_of_message -> 0x0D, position -> 0, first_appel -> 1)
+ * @param @ de la structure a initialiser
+ * @retval None
+ */
+void init_t_transmission(struct t_transmission * transmission) {
+ int i;
+ for (i=0; imessage[i] = ':';
+ } else {
+ transmission->message[i] = 0;
+ }
+ }
+ transmission->end_of_message = 0x0D;
+ transmission->position = 0;
+ transmission->first_appel = 1;
+}
+
+/**
+ * @brief Convertir un entier de 2 chiffres en un string.
+ * @note UNIQUEMENT DES ENTIERS DE 2 DIGITS (eventuellement 1 digit).
+ * @param n : l'entier a convertir
+ * buffer : @ du buffer ou stocker la conversion
+ * @retval None
+ */
+void itoa(int n, char * buffer) {
+ buffer[0] = (n/10) + 0x30;
+ buffer[1] = (n % 10) + 0x30;
+}
+
+/**
+ * @brief Ecrit l'heure dans une t_transmission.
+ * @note L'heure est inscrite dans le champs message de la structure
+ * @param @ de la structure dont on souhaite modifier le message
+ * @retval None
+ */
+void recuperer_heure(struct t_transmission * transmission) {
+ itoa(Chrono_Time.Min, transmission->message);
+ itoa(Chrono_Time.Sec, &(transmission->message[3]));
+ itoa(Chrono_Time.Hund, &(transmission->message[6]));
+}
+
// déclaration callback appelé toute les 10ms
void Chrono_Task_10ms(void);
+/**
+ * @brief Configure les IOs utiles pour les boutons et la LED.
+ * @note Bouton Reset : PinC13 -> floating input
+ Bouton Start/Stop : PinC8 -> floating input
+ LED : PinC10 -> Opendrain 2MHz
+ * @param None
+ * @retval None
+ */
void Chrono_Conf_io(void) {
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
@@ -33,7 +100,52 @@ void Chrono_Conf_io(void) {
LL_GPIO_SetOutputPin(GPIOC, LL_GPIO_PIN_10); // Car logique négative
}
-void Chrono_Background(void) {
+/**
+ * @brief Configure les USARTs
+ * @note Data : 8bits
+ Vitesse : 19200Bd
+ Parity : None
+ Stop Bit : 1
+ Sens : Tx only
+ GPIOs relatif a TX initialisés
+ * @param USARTx : USART a configurer
+ * @retval None
+ */
+void Chrono_Conf_UART(USART_TypeDef * USARTx) {
+ if (USARTx == USART1) {
+ LL_APB2_GRP1_EnableClock(RCC_APB2ENR_USART1EN);// ON la clock
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); //ON la clock du port de TX
+ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE); //ConfigTX
+ } else if (USARTx == USART2) {
+ LL_APB1_GRP1_EnableClock(RCC_APB1ENR_USART2EN); // ON la clock
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); //ON la clock du port de TX
+ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_2, LL_GPIO_MODE_ALTERNATE); //ConfigTX
+ } else if (USARTx == USART3) {
+ LL_APB1_GRP1_EnableClock(RCC_APB1ENR_USART3EN);// ON la clock
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); //ON la clock du port de TX
+ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE); //ConfigTX
+ }
+
+ LL_USART_InitTypeDef USART_InitStruct;
+ LL_USART_StructInit(&USART_InitStruct);
+ USART_InitStruct.BaudRate = 19200; //Set Baud rate -> 19200Bd
+ USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; //Set data width -> 8bits
+ USART_InitStruct.Parity = LL_USART_PARITY_NONE;// Disable Parity
+ USART_InitStruct.StopBits = LL_USART_STOPBITS_1;// Set stop bit -> 1
+ USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX;//Set sens -> TX Only
+ LL_USART_Init(USARTx, &USART_InitStruct);// Applique les modifs
+ LL_USART_Enable(USARTx);// Rend l'USART enable A FAIRE EN DERNIER
+}
+
+
+/**
+ * @brief Gere les taches de fond : USART et Boutons
+ * @param USARTx : USART sur laquelle on souhaite discuter (doit avoir été initialisée)
+ * @retval None
+ */
+void Chrono_Background(USART_TypeDef * USARTx) {
+
+ // GESTION DES BOUTONS
static int isAllume = 1;
static int Start_Stop_Button_Last_State = 0;
static int Reset_Button_Last_State = 1;
@@ -65,15 +177,36 @@ void Chrono_Background(void) {
Chrono_Start();
}
}
+
+ //GESTION DE L'AFFICHAGE
+ static struct t_transmission transmission = {"", 0x0D, 0, 1};
+
+ if (drapeau) {
+ if (transmission.first_appel) {
+ recuperer_heure(&transmission);
+ transmission.first_appel = 0;
+ }
+ if (LL_USART_IsActiveFlag_TXE(USARTx)) {
+ if (transmission.position < TAILLE_MESSAGE) {
+ LL_USART_TransmitData8(USARTx, (uint8_t)(transmission.message[transmission.position]));
+ transmission.position += 1;
+ } else {
+ LL_USART_TransmitData8(USARTx, (uint8_t)(transmission.end_of_message));
+ init_t_transmission(&transmission);
+ drapeau = 0;
+ }
+ }
+ }
}
/**
- * @brief Configure le chronomètre.
+ * @brief Configure le chronomètre (Timer, IO, USART).
* @note A lancer avant toute autre fonction.
* @param Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
+ * USARTx : indique l'USART a utiliser pour communiquer avec le PC
* @retval None
*/
-void Chrono_Conf(TIM_TypeDef * Timer)
+void Chrono_Conf(TIM_TypeDef * Timer, USART_TypeDef * USARTx)
{
// Reset Time
Chrono_Time.Hund=0;
@@ -86,14 +219,18 @@ void Chrono_Conf(TIM_TypeDef * Timer)
// Réglage Timer pour un débordement à 10ms
MyTimer_Conf(Chrono_Timer,999, 719);
+ // Configuration des IO
+ Chrono_Conf_io();
+
+ // Config du UART
+ Chrono_Conf_UART(USARTx);
+
+ // LES IT TOUJOURS A LA FIN
// Réglage interruption du Timer avec callback : Chrono_Task_10ms()
MyTimer_IT_Conf(Chrono_Timer, Chrono_Task_10ms,3);
// Validation IT
MyTimer_IT_Enable(Chrono_Timer);
-
- // Configuration des IO
- Chrono_Conf_io();
}
@@ -137,6 +274,9 @@ void Chrono_Reset(void)
Chrono_Time.Hund=0;
Chrono_Time.Sec=0;
Chrono_Time.Min=0;
+
+ // Previens transimition OK
+ drapeau = 1;
}
@@ -185,7 +325,7 @@ void Chrono_Task_10ms(void)
{
Chrono_Time.Hund=0;
}
-
+ drapeau = 1;
}
diff --git a/Services/Chrono.h b/Services/Chrono.h
index 4b03760..848c8d1 100644
--- a/Services/Chrono.h
+++ b/Services/Chrono.h
@@ -35,7 +35,7 @@ Les fonctions qui g
* @retval None
*/
-void Chrono_Background(void);
+void Chrono_Background(USART_TypeDef * USARTx);
//=======================================================================================//
@@ -59,7 +59,7 @@ typedef struct {
* @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
-void Chrono_Conf(TIM_TypeDef * Timer);
+void Chrono_Conf(TIM_TypeDef * Timer, USART_TypeDef * USARTx);
diff --git a/Src/main.c b/Src/main.c
index b209102..79e2d48 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -40,7 +40,7 @@ int main(void)
/* Add your application code here */
// Configuration chronomètre
- Chrono_Conf(TIM3);
+ Chrono_Conf(TIM3, USART2);
// Lancement chronomètre
Chrono_Start();
@@ -50,7 +50,7 @@ int main(void)
/* Infinite loop */
while (1)
{
- Chrono_Background();
+ Chrono_Background(USART2);
}
}