diff --git a/driver/timer.c b/driver/timer.c index 768cc8b..0d15cd4 100644 --- a/driver/timer.c +++ b/driver/timer.c @@ -4,6 +4,7 @@ void plantage(void) { while(1); } + void (*IT_Tim1) (void) = plantage; void (*IT_Tim2) (void) = plantage; void (*IT_Tim3) (void) = plantage; @@ -168,10 +169,10 @@ if(Timer == TIM1) MyGPIO_Init(&PWM_OUT); } -void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle) +void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned int DutyCycle) { unsigned int RC; - RC = ((Timer->ARR)/100)*(DutyCycle); + RC = ((Timer->ARR)*(DutyCycle)/10000); switch (Channel) { case 1: Timer->CCR1 = RC; diff --git a/driver/timer.h b/driver/timer.h index 281867e..6c63f90 100644 --- a/driver/timer.h +++ b/driver/timer.h @@ -11,7 +11,7 @@ typedef struct { void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer); void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)); void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel); -void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle); +void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned int DutyCycle); #define MyTimer_Base_Start(Tim) (Tim.Timer->CR1 |= TIM_CR1_CEN) #define MyTimer_Base_Stop(Tim) (Tim.Timer->CR1 &= ~TIM_CR1_CEN) diff --git a/implementation/motoreducteur.c b/implementation/motoreducteur.c new file mode 100644 index 0000000..b081215 --- /dev/null +++ b/implementation/motoreducteur.c @@ -0,0 +1,41 @@ +#include "motoreducteur.h" +#include "timer.h" +#include "gpio.h" + +void MyMotor_Init() +{ + MyTimer_Struct_Typedef Timer; + MyGPIO_Struct_TypeDef Pin_Direction; + + //F de 50kHz + Timer.Timer = TIM3; + Timer.ARR = 3599; //72Mhz / 50kHz = 1440 et 1440*1 = 1440 + Timer.PSC = 0; + + Pin_Direction.GPIO = GPIOB; + Pin_Direction.GPIO_Pin = 1; + Pin_Direction.GPIO_Conf = Out_PullUp; + + MyTimer_Base_Init(&Timer); + MyGPIO_Init(&Pin_Direction); + + //Pin Timer 3 Channel 3 PB0 + MyTimer_PWM(TIM3, 3); + MyTimer_DutyCycle(TIM3, 3, 0); + + MyTimer_Base_Start(Timer); + MyMotor_ChangeDirection(ANTIHOR); +} + +void MyMotor_ChangeSpeed(unsigned int DC) +{ + MyTimer_DutyCycle(TIM3, 3, DC); +} + +void MyMotor_ChangeDirection(uint8_t Sens) +{ + if (Sens == HORAIRE) + MyGPIO_Set(GPIOB, 1); + if (Sens == ANTIHOR) + MyGPIO_Reset(GPIOB, 1); +} diff --git a/implementation/motoreducteur.h b/implementation/motoreducteur.h new file mode 100644 index 0000000..a7c9db0 --- /dev/null +++ b/implementation/motoreducteur.h @@ -0,0 +1,12 @@ +#ifndef MYMOTOR_H +#define MYMOTOR_H +#include "stm32f10x.h" + +#define HORAIRE 0x1 +#define ANTIHOR 0x0 + +void MyMotor_Init(); +void MyMotor_ChangeSpeed(unsigned int DC); +void MyMotor_ChangeDirection(uint8_t Sens); + +#endif diff --git a/implementation/rtc.c b/implementation/rtc.c new file mode 100644 index 0000000..86e15b4 --- /dev/null +++ b/implementation/rtc.c @@ -0,0 +1,37 @@ +#include "rtc.h" + +void plantage_i2C(void) { + while(1); +} + +void (*IT_I2C_Err) (void) = plantage_i2C; + +void MyRTC_Init() +{ + MyI2C_Init(I2C1, 15, IT_I2C_Err); +} + +void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year) +{ + MyI2C_RecSendData_Typedef data; + char regCopy = 0; + + data.SlaveAdress7bits = 0x68; + data.Ptr_Data = ®Copy; + data.Nb_Data = 1; + + MyI2C_GetString(I2C1, 0x00, &data); + *sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F); + MyI2C_GetString(I2C1, 0x01, &data); + *min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F); + MyI2C_GetString(I2C1, 0x02, &data); + *hour = 0; + MyI2C_GetString(I2C1, 0x03, &data); + *day = (regCopy & 0x07); + MyI2C_GetString(I2C1, 0x04, &data); + *date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F); + MyI2C_GetString(I2C1, 0x05, &data); + *month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F); + MyI2C_GetString(I2C1, 0x06, &data); + *year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000; +} \ No newline at end of file diff --git a/implementation/rtc.h b/implementation/rtc.h new file mode 100644 index 0000000..caaa6ba --- /dev/null +++ b/implementation/rtc.h @@ -0,0 +1,9 @@ +#ifndef GPIODRIVER_H +#define GPIODRIVER_H +#include "stm32f10x.h" +#include "MyI2C.h" + +void MyRTC_Init(); +void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year); + +#endif diff --git a/implementation/servo.c b/implementation/servo.c new file mode 100644 index 0000000..cf41537 --- /dev/null +++ b/implementation/servo.c @@ -0,0 +1,30 @@ +#include "servo.h" +#include "timer.h" + +void MyServo_Init() +{ + MyTimer_Struct_Typedef Timer; + + //Période de 20ms -> F de 50Hz + Timer.Timer = TIM2; + Timer.ARR = 3599; //20*180 (angle) = 3600 + Timer.PSC = 399; //72Mhz / 50Hz = 1.44Mhz et 3600*400 = 1.44M + + MyTimer_Base_Init(&Timer); + + //Pin Timer 2 Channel 1 PA0 + MyTimer_PWM(TIM2, 1); + MyTimer_DutyCycle(TIM2, 1, 750); + + MyTimer_Base_Start(Timer); +} + +void MyServo_ChangeAngle(uint8_t Angle) +{ + if (Angle > 180) + Angle = 180; + + int DC = 500 + (Angle * 500 / 180); + + MyTimer_DutyCycle(TIM2, 1, DC); +} diff --git a/implementation/servo.h b/implementation/servo.h new file mode 100644 index 0000000..bc9f4f7 --- /dev/null +++ b/implementation/servo.h @@ -0,0 +1,13 @@ +#ifndef MYSERVO_H +#define MYSERVO_H +#include "stm32f10x.h" + +/* +180 correspond à 0° +0 correspond à 90° +*/ + +void MyServo_Init(); +void MyServo_ChangeAngle(uint8_t Angle); + +#endif diff --git a/keilproject/RTE/_R_el/RTE_Components.h b/keilproject/RTE/_R_el/RTE_Components.h index 849a0e6..d0354e4 100644 --- a/keilproject/RTE/_R_el/RTE_Components.h +++ b/keilproject/RTE/_R_el/RTE_Components.h @@ -3,7 +3,7 @@ * Auto generated Run-Time-Environment Configuration File * *** Do not modify ! *** * - * Project: 'gpiodriver' + * Project: 'voilier' * Target: 'Réel' */ diff --git a/keilproject/Source/Principale.c b/keilproject/Source/Principale.c index e4d5a23..a0cfee4 100644 --- a/keilproject/Source/Principale.c +++ b/keilproject/Source/Principale.c @@ -1,8 +1,19 @@ #include "stm32f10x.h" -#include "../../driver/MyI2C.h" -#include "../../driver/MySPI.h" +#include "servo.h" +#include "motoreducteur.h" +#include "rtc.h" int main (void) { - while(1){}; - } + MyServo_Init(); + MyServo_ChangeAngle(179); + //MyMotor_Init(); + + //MyMotor_ChangeSpeed(2000); + //MyMotor_ChangeDirection(HORAIRE); + + MyRTC_Init(); + MyRTC_GetTime(); + + while(1){}; +} diff --git a/keilproject/voilier.uvoptx b/keilproject/voilier.uvoptx index b667108..7292b15 100644 --- a/keilproject/voilier.uvoptx +++ b/keilproject/voilier.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -142,23 +142,23 @@ 0 0 - 15 + 13 1 -
134218740
+
0
0 0 0 0 0 - 1 + 0 .\Source\Principale.c - \\cool_Simule\Source/Principale.c\15 +
1 0 - 19 + 12 1
0
0 @@ -174,6 +174,38 @@ 2 0 + 15 + 1 +
134218740
+ 0 + 0 + 0 + 0 + 0 + 1 + .\Source\Principale.c + + \\cool_Simule\Source/Principale.c\15 +
+ + 3 + 0 + 19 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Source\Principale.c + + +
+ + 4 + 0 7 1
0
@@ -188,7 +220,7 @@
- 3 + 5 0 8 1 @@ -332,7 +364,7 @@ 1 0 - 0 + 1 18 @@ -387,7 +419,7 @@ 0 ST-LINKIII-KEIL_SWO - -U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) + -U066AFF504955857567212155 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) 0 @@ -414,7 +446,55 @@ 0 0 - 6 + 24 + 1 +
134219864
+ 0 + 0 + 0 + 0 + 0 + 1 + C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\implementation\rtc.c + + \\cool_reel\../implementation/rtc.c\24 +
+ + 1 + 0 + 25 + 1 +
134219874
+ 0 + 0 + 0 + 0 + 0 + 1 + C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\implementation\rtc.c + + \\cool_reel\../implementation/rtc.c\25 +
+ + 2 + 0 + 16 + 1 +
134221212
+ 0 + 0 + 0 + 0 + 0 + 1 + C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\keilproject\Source\Principale.c + + \\cool_reel\Source/Principale.c\16 +
+ + 3 + 0 + 23 1
0
0 @@ -423,7 +503,7 @@ 0 0 0 - .\Source\Principale.c + ..\implementation\rtc.c
@@ -530,6 +610,98 @@ 0 0 + + 2 + 3 + 1 + 0 + 0 + 0 + ..\driver\gpio.c + gpio.c + 0 + 0 + + + 2 + 4 + 1 + 0 + 0 + 0 + ..\driver\timer.c + timer.c + 0 + 0 + + + 2 + 5 + 1 + 0 + 0 + 0 + ..\driver\uart.c + uart.c + 0 + 0 + + + 2 + 6 + 1 + 0 + 0 + 0 + ..\driver\adc.c + adc.c + 0 + 0 + + + + + MesImplementations + 1 + 0 + 0 + 0 + + 3 + 7 + 1 + 0 + 0 + 0 + ..\implementation\servo.c + servo.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\implementation\motoreducteur.c + motoreducteur.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\implementation\rtc.c + rtc.c + 0 + 0 + @@ -542,7 +714,7 @@ ::Device - 1 + 0 0 0 1 diff --git a/keilproject/voilier.uvprojx b/keilproject/voilier.uvprojx index cda4e65..fdc3f2a 100644 --- a/keilproject/voilier.uvprojx +++ b/keilproject/voilier.uvprojx @@ -339,7 +339,7 @@ - .\Include + .\Include;..\driver;..\implementation @@ -398,6 +398,46 @@ 4 ..\driver\Lib_Com_Periph_2022.lib + + gpio.c + 1 + ..\driver\gpio.c + + + timer.c + 1 + ..\driver\timer.c + + + uart.c + 1 + ..\driver\uart.c + + + adc.c + 1 + ..\driver\adc.c + + + + + MesImplementations + + + servo.c + 1 + ..\implementation\servo.c + + + motoreducteur.c + 1 + ..\implementation\motoreducteur.c + + + rtc.c + 1 + ..\implementation\rtc.c + @@ -741,7 +781,7 @@ - .\Include + .\Include;..\driver;..\implementation @@ -800,6 +840,46 @@ 4 ..\driver\Lib_Com_Periph_2022.lib + + gpio.c + 1 + ..\driver\gpio.c + + + timer.c + 1 + ..\driver\timer.c + + + uart.c + 1 + ..\driver\uart.c + + + adc.c + 1 + ..\driver\adc.c + + + + + MesImplementations + + + servo.c + 1 + ..\implementation\servo.c + + + motoreducteur.c + 1 + ..\implementation\motoreducteur.c + + + rtc.c + 1 + ..\implementation\rtc.c +