Merge branch 'alix' of boujon/voilier-team-1 into master

ok
This commit is contained in:
Yohan Boujon 2023-04-07 12:57:08 +02:00 committed by Gitea
commit 2a1180c521
12 changed files with 428 additions and 22 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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);
}

View file

@ -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

37
implementation/rtc.c Normal file
View file

@ -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 = &regCopy;
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;
}

9
implementation/rtc.h Normal file
View file

@ -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

30
implementation/servo.c Normal file
View file

@ -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);
}

13
implementation/servo.h Normal file
View file

@ -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

View file

@ -3,7 +3,7 @@
* Auto generated Run-Time-Environment Configuration File
* *** Do not modify ! ***
*
* Project: 'gpiodriver'
* Project: 'voilier'
* Target: 'Réel'
*/

View file

@ -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)
{
MyServo_Init();
MyServo_ChangeAngle(179);
//MyMotor_Init();
//MyMotor_ChangeSpeed(2000);
//MyMotor_ChangeDirection(HORAIRE);
MyRTC_Init();
MyRTC_GetTime();
while(1){};
}
}

View file

@ -75,7 +75,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
<IsCurrentTarget>0</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -142,23 +142,23 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>15</LineNumber>
<LineNumber>13</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218740</Address>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_Simule\Source/Principale.c\15</Expression>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>19</LineNumber>
<LineNumber>12</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
@ -174,6 +174,38 @@
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>15</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218740</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_Simule\Source/Principale.c\15</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>19</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>4</Number>
<Type>0</Type>
<LineNumber>7</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
@ -188,7 +220,7 @@
<Expression></Expression>
</Bp>
<Bp>
<Number>3</Number>
<Number>5</Number>
<Type>0</Type>
<LineNumber>8</LineNumber>
<EnabledFlag>1</EnabledFlag>
@ -332,7 +364,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -387,7 +419,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-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)</Name>
<Name>-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)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -414,7 +446,55 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>6</LineNumber>
<LineNumber>24</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219864</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\implementation\rtc.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_reel\../implementation/rtc.c\24</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>25</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219874</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\implementation\rtc.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_reel\../implementation/rtc.c\25</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>16</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134221212</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\keilproject\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_reel\Source/Principale.c\16</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>23</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
@ -423,7 +503,7 @@
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<Filename>..\implementation\rtc.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
@ -530,6 +610,98 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>3</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\gpio.c</PathWithFileName>
<FilenameWithoutPath>gpio.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\timer.c</PathWithFileName>
<FilenameWithoutPath>timer.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>5</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\uart.c</PathWithFileName>
<FilenameWithoutPath>uart.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\adc.c</PathWithFileName>
<FilenameWithoutPath>adc.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\servo.c</PathWithFileName>
<FilenameWithoutPath>servo.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\motoreducteur.c</PathWithFileName>
<FilenameWithoutPath>motoreducteur.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>9</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\rtc.c</PathWithFileName>
<FilenameWithoutPath>rtc.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@ -542,7 +714,7 @@
<Group>
<GroupName>::Device</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>

View file

@ -339,7 +339,7 @@
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath>.\Include</IncludePath>
<IncludePath>.\Include;..\driver;..\implementation</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -398,6 +398,46 @@
<FileType>4</FileType>
<FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath>
</File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\gpio.c</FilePath>
</File>
<File>
<FileName>timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\timer.c</FilePath>
</File>
<File>
<FileName>uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\uart.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\adc.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<Files>
<File>
<FileName>servo.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\servo.c</FilePath>
</File>
<File>
<FileName>motoreducteur.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\motoreducteur.c</FilePath>
</File>
<File>
<FileName>rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\rtc.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -741,7 +781,7 @@
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath>.\Include</IncludePath>
<IncludePath>.\Include;..\driver;..\implementation</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -800,6 +840,46 @@
<FileType>4</FileType>
<FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath>
</File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\gpio.c</FilePath>
</File>
<File>
<FileName>timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\timer.c</FilePath>
</File>
<File>
<FileName>uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\uart.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\adc.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<Files>
<File>
<FileName>servo.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\servo.c</FilePath>
</File>
<File>
<FileName>motoreducteur.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\motoreducteur.c</FilePath>
</File>
<File>
<FileName>rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\rtc.c</FilePath>
</File>
</Files>
</Group>
<Group>