Correction interruption prof
This commit is contained in:
parent
4d69e527e5
commit
1c84636b75
5 changed files with 100 additions and 13 deletions
|
@ -11,7 +11,7 @@ typedef struct
|
|||
} MyTimer_Struct_TypeDef;
|
||||
|
||||
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer, void (*fct)(void));
|
||||
void MyTimer_Base_Start(TIM_TypeDef * Timer);
|
||||
void MyTimer_Base_Stop(TIM_TypeDef * Timer);
|
||||
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle);
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
//----------------------INIT--------------------//
|
||||
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){
|
||||
|
||||
MyGPIO_Struct_TypeDef * GPIO_ADC;
|
||||
//Division par 6 de la clock (72MHz) pour l'ADC (14MHz max)
|
||||
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
|
||||
|
||||
//Selection du channel PC0 pour l'ADC
|
||||
MyGPIO_Struct_TypeDef * GPIO_ADC;
|
||||
|
||||
GPIO_ADC->GPIO = GPIOC;
|
||||
GPIO_ADC->GPIO_Conf = In_Analog;
|
||||
GPIO_ADC->GPIO_Pin = 0;
|
||||
|
@ -42,3 +43,9 @@ void MyADC_Base_Stop(ADC_TypeDef * ADC){
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------HANDLER---------------//
|
||||
void ADC1_2_IRQHandler (void) {
|
||||
ADC1->SR &= ~(1<<1); //RAZ du flag end of conversion
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#include "Driver_Timer.h"
|
||||
|
||||
|
||||
void (*Ptrfct)(void);
|
||||
|
||||
//-----------------------INITIALISATION TIMER---------------------//
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer, void (*fct)(void)){
|
||||
|
||||
Ptrfct=fct;
|
||||
|
||||
if(Timer->Timer == TIM1){
|
||||
//RCC->APB2ENR |= 0x0001<<11;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
|
@ -44,3 +50,11 @@ void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){
|
|||
Timer->Timer->CCER |= TIM_CCER_CC1E; // Canal CH1 validé par bit CC1E (registre CCER)
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
|
||||
}
|
||||
|
||||
|
||||
//------------------------HANDLER--------------------//
|
||||
void TIM2_IRQHandler (void)
|
||||
{
|
||||
TIM2->SR &= ~(1<<0);
|
||||
Ptrfct();
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -143,7 +143,63 @@
|
|||
<Name>-U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>9</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>..\Drivers\Sources\Driver_Timer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>36</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>.\Sources\Main.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>59</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>..\Drivers\Sources\Driver_Timer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>Ptrfct</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
@ -158,7 +214,7 @@
|
|||
<viewmode>1</viewmode>
|
||||
<vrSel>0</vrSel>
|
||||
<aSym>0</aSym>
|
||||
<aTbox>1</aTbox>
|
||||
<aTbox>0</aTbox>
|
||||
<AscS1>0</AscS1>
|
||||
<AscS2>0</AscS2>
|
||||
<AscS3>0</AscS3>
|
||||
|
@ -263,7 +319,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
#include "Driver_GPIO.h"
|
||||
#include "Driver_Timer.h"
|
||||
|
||||
void Timer_interup(void);
|
||||
void ADC_interup(void);
|
||||
|
||||
int main (void){
|
||||
//Déclaration d'un Timer 500 ms
|
||||
MyTimer_Struct_TypeDef TIM500ms;
|
||||
//Init Timer 2 et Test
|
||||
TIM500ms.Timer = TIM2;
|
||||
TIM500ms.PSC = 7200; // =0.5ms(calculé à partir de la fréquence du micro)
|
||||
TIM500ms.ARR = 5000;
|
||||
MyTimer_Base_Init(&TIM500ms);
|
||||
TIM500ms.PSC = 7200-1; // =0.5ms(calculé à partir de la fréquence du micro)
|
||||
TIM500ms.ARR = 5000-1;
|
||||
MyTimer_Base_Init(&TIM500ms, Timer_interup);
|
||||
|
||||
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
|
||||
//TIM2->DIER |= TIM_DIER_UIE ;
|
||||
NVIC->ISER[0] |= 1<<TIM2_IRQn ; //INTERRUPTION COEUR
|
||||
NVIC->IP[TIM2_IRQn] = 2<< 4 ;
|
||||
|
||||
|
||||
MyTimer_Base_Start(TIM500ms.Timer);
|
||||
|
||||
MyTimer_PWM(&TIM500ms, 50);
|
||||
|
@ -27,8 +31,14 @@ int main (void){
|
|||
}
|
||||
|
||||
|
||||
void TIM2_IRQHandler (void)
|
||||
//Interuption du programme par trigger du timer
|
||||
void Timer_interup(void)
|
||||
{
|
||||
MyGPIO_Toggle(GPIOA,5);
|
||||
TIM2->SR &= ~(1<<0);
|
||||
}
|
||||
|
||||
//Interruption du programme par trigger de l'ADC
|
||||
void ADC_interrup(void)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in a new issue