From 3aa80037769457c3902ffe3ef78c1ceb81ae66fd Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Sun, 22 Nov 2020 13:05:16 +0100
Subject: [PATCH] GPIO configuration fixed - Moteur OK
---
MDK-ARM/Project.uvoptx | 28 ++++++----------------------
MyDrivers/MyPWM.h | 8 ++++++--
Services/Moteur.c | 29 +++++++++++++++++------------
Services/Moteur.h | 6 ++++++
Src/main.c | 13 ++++++++++---
5 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index 6c5132a..aa749d9 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -354,9 +354,9 @@
0
0
- 38
+ 25
1
- 134219162
+ 134219120
0
0
0
@@ -365,23 +365,7 @@
1
F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
- \\NUCLEO_F103RB\../Services/Moteur.c\38
-
-
- 1
- 0
- 26
- 1
- 134219126
- 0
- 0
- 0
- 0
- 0
- 1
- F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
-
- \\NUCLEO_F103RB\../Services/Moteur.c\26
+ \\NUCLEO_F103RB\../Services/Moteur.c\25
@@ -395,7 +379,7 @@
1
0
- Psc
+ My_GPIO_Init_Struct
0
@@ -445,12 +429,12 @@
0
((porta & 0x00000002) >> 1 & 0x2) >> 1
- 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F1800000000000000000000000000000000000000320F0008
+ 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0B00000000000000000000000000000000000000320F0008
1
((porta & 0x00000004) >> 2 & 0x4) >> 2
- 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F1800000000000000000000000000000000000000320F0008
+ 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0B00000000000000000000000000000000000000320F0008
diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h
index 6702b92..562cb06 100644
--- a/MyDrivers/MyPWM.h
+++ b/MyDrivers/MyPWM.h
@@ -1,5 +1,7 @@
-#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
-#include "stm32f1xx_ll_tim.h"
+#ifndef PWM_H
+#define PWM_H
+
+#include "stm32f103xb.h"
void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
@@ -7,3 +9,5 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2);
void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel);
+
+#endif
diff --git a/Services/Moteur.c b/Services/Moteur.c
index 3a7e749..19640e9 100644
--- a/Services/Moteur.c
+++ b/Services/Moteur.c
@@ -1,13 +1,16 @@
+
#include "Moteur.h"
#include "MyPWM.h"
#include "MyTimer.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_gpio.h"
+#include "stm32f1xx_ll_tim.h"
-//Fpwm = 10kHz
void Moteur_Conf(void) {
+
+ //Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
int Arr = 0x1C1F;
int Psc = 0x0;
@@ -15,24 +18,26 @@ void Moteur_Conf(void) {
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
//Config broche PA2 -> Sens
- LL_GPIO_InitTypeDef* My_GPIO_Init_Struct;
+ LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
- LL_GPIO_StructInit(My_GPIO_Init_Struct);
+ LL_GPIO_StructInit(&My_GPIO_Init_Struct);
- My_GPIO_Init_Struct->Pin = LL_GPIO_PIN_2;
- My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_OUTPUT;
- My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+ My_GPIO_Init_Struct.Pin = PinSens;
+ My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
+ My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- LL_GPIO_Init(GPIOA, My_GPIO_Init_Struct);
+ LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
//Config broche PA1 -> PWM
- LL_GPIO_StructInit(My_GPIO_Init_Struct);
+ LL_GPIO_StructInit(&My_GPIO_Init_Struct);
+
+ My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
+ My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
+ My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+
+ LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
- My_GPIO_Init_Struct->Pin = LL_GPIO_PIN_1;
- My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_ALTERNATE;
- My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- LL_GPIO_Init(GPIOA, My_GPIO_Init_Struct);
//Activation horloge Timer
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
diff --git a/Services/Moteur.h b/Services/Moteur.h
index 69ccaae..32cdb88 100644
--- a/Services/Moteur.h
+++ b/Services/Moteur.h
@@ -1,3 +1,7 @@
+#ifndef MOTEUR_H
+#define MOTEUR_H
+
+#include "stm32f103xb.h"
#define PinSens LL_GPIO_PIN_2
#define PinPWM LL_GPIO_PIN_1
@@ -10,3 +14,5 @@ void Moteur_Conf(void);
void Moteur_Speed(int speedPercentage);
void Moteur_Sens(int sens);
+
+#endif
diff --git a/Src/main.c b/Src/main.c
index bf51d3f..64a2b92 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -45,13 +45,20 @@ int main(void)
//INIT GPIO MARCHE PAS->PB PIN
Moteur_Conf();
- Moteur_Speed(50);
- Moteur_Sens(1);
+ Moteur_Speed(30);
+ Moteur_Sens(0);
/* Infinite loop */
- while (1)
+ for (int i =0; i<0xFFFF; i++)
{
}
+
+ Moteur_Speed(60);
+ Moteur_Sens(1);
+
+ while (1)
+ {
+ }
}