Compare commits

...

4 commits

Author SHA1 Message Date
afcef9950d UART Soon finish 2023-03-31 12:19:05 +02:00
6d6f9a112f Interrupt Begin 2023-03-22 14:36:53 +01:00
cc60bd40f1 Timers Done 2023-03-21 16:38:24 +01:00
d3d48cf176 Compteur Done 2023-03-21 16:28:46 +01:00
7 changed files with 212 additions and 14 deletions

View file

@ -0,0 +1,38 @@
#include "Driver_timers.h"
void timer_init(MyTimer_Struct_TypeDef * Timer){
if(Timer->Timer == TIM1){
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
}
if(Timer->Timer == TIM2){
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
}
if(Timer->Timer == TIM3){
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
}
if(Timer->Timer == TIM4){
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
}
}
void MyTimer_Start(MyTimer_Struct_TypeDef *Timer)
{
Timer->Timer->CR1 |= TIM_CR1_CEN; // Démarre le Timer
}
void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer)
{
Timer->Timer->CR1 &= ~TIM_CR1_CEN; // Arrête le Timer
}
void MyTimer_EnableInterrupt(MyTimer_Struct_TypeDef *Timer) {
Timer->Timer->DIER |= TIM_DIER_UIE; // Active l'interruption "Update" du Timer
NVIC->ISER[Timer->IRQn / 32] = (1 << Timer->IRQn); // Pour que ce soit générique : On divise IRQn par 32 pour avoir le ISER[] correspondant. On fait également le modulo 32 de IRQn pour avoir un nombre entre 0 et 31 correspondant au setting
}
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer , char Channel){
}

View file

@ -0,0 +1,27 @@
#ifndef MYTIMER_H
#define MYTIMER_H
#include "stm32f10x.h"
typedef struct
{
TIM_TypeDef * Timer;
unsigned short ARR;
unsigned short PSC;
} MyTimer_Struct_TypeDef;
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
void timer_init(MyTimer_Struct_TypeDef * Timer);
void MyTimer_Start(MyTimer_Struct_TypeDef *Timer);
void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer);
void MyTimer_EnableInterrupt(MyTimer_Struct_TypeDef *Timer);
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer , char Channel);
#define MyTimer_Base_Start(Timer)
#define MyTimer_Base_Stop(Timer)
#endif

View file

@ -1,15 +1,18 @@
#include "stm32f10x.h"
#include "Driver_GPIO.h"
#include "Driver_timers.h"
// PA5 LED
// PC13 BP
MyGPIO_Struct_TypeDef LED;
MyTimer_Struct_TypeDef Timer_500ms;
int delay(){
int i;
for(i=0;i<1000000;i++);
int i;
for(i=0;i<1000000;i++);
}
@ -30,17 +33,44 @@ int main ( void )
MyGPIO_Init(&LED);
Timer_500ms.Timer = TIM2;
Timer_500ms.PSC = 7200; //(1/72Mhz)/7200=0.1ms
Timer_500ms.ARR = 5000; //0.1*5000 = 500ms
timer_init(&Timer_500ms);
TIM2->DIER|=1<<0; //Interruption périph
NVIC->ISER[0] |= 1>>TIM2_IRQn; //Interruption Coeur
NVIC->IP[TIM2_IRQn] = 2 <<4;
MyTimer_Start(&Timer_500ms);
while(1)
{
if(MyGPIO_Read(GPIOC, 13) == 0)
{
//if(MyGPIO_Read(GPIOC, 13) == 0)
//{
MyGPIO_Set(GPIOA, 5);
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); //CNT registre qui gère le retour à 0
MyGPIO_Reset(GPIOA, 5);
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1);
//}
/* OU
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); //CNT registre qui gère le retour à 0
MyGPIO_Toggle(GPIOA, 5);
delay();
}
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); //CNT registre qui gère le retour à 0
*/
}
}
void TIM2_IRQHandler (void){
MyGPIO_Toggle(GPIOA, 5);
TIM2->SR &= ~(1<<0);
}

View file

@ -75,7 +75,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -125,7 +125,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGDARM</Key>
<Name>(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=-1,-1,-1,-1,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=-1,-1,-1,-1,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)</Name>
<Name>(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=942,144,1363,571,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,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=1148,152,1742,903,0)(132=-1,-1,-1,-1,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)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -138,14 +138,95 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>57</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>.\Src\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>44</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>.\Src\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>74</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218650</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier\Projet_Voilier\ProjetsKEIL\Projet_1\Src\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1_Simu\Src/Principal.c\74</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>44</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218794</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier\Projet_Voilier\ProjetsKEIL\Projet_1\Src\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1_Simu\Src/Principal.c\44</Expression>
</Bp>
<Bp>
<Number>4</Number>
<Type>0</Type>
<LineNumber>57</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218828</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier\Projet_Voilier\ProjetsKEIL\Projet_1\Src\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1_Simu\Src/Principal.c\57</Expression>
</Bp>
</Breakpoint>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
<DebugFlag>
<trace>0</trace>
<periodic>1</periodic>
<aLwin>1</aLwin>
<aLwin>0</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer2>0</aSer2>
@ -245,7 +326,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
<IsCurrentTarget>0</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -290,7 +371,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGTARM</Key>
<Name>(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=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,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=-1,-1,-1,-1,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)(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)</Name>
<Name>(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=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,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=963,134,1557,828,0)(132=-1,-1,-1,-1,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)(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)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -414,6 +495,18 @@
<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>..\Drivers\Driver_timers.c</PathWithFileName>
<FilenameWithoutPath>Driver_timers.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>

View file

@ -339,7 +339,7 @@
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath>.\Include</IncludePath>
<IncludePath>.\Include;..\Drivers</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -398,6 +398,11 @@
<FileType>1</FileType>
<FilePath>..\Drivers\Driver_GPIO.c</FilePath>
</File>
<File>
<FileName>Driver_timers.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Driver_timers.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -800,6 +805,11 @@
<FileType>1</FileType>
<FilePath>..\Drivers\Driver_GPIO.c</FilePath>
</File>
<File>
<FileName>Driver_timers.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Driver_timers.c</FilePath>
</File>
</Files>
</Group>
<Group>