Projet_voilier2/Projet_DevDrivers/Sources/Principal.c
2023-04-07 15:19:56 +02:00

79 lines
1.4 KiB
C

#include "stm32f10x.h"
#include "GPIO.h"
#include "TIMER.h"
#include "MyI2C.h"
#include "MySPI.h"
#include "Rouli.h"
#include <stdio.h>
void Mafonction_IT (void);
MyGPIO_Struct_TypeDef PA5;
MyGPIO_Struct_TypeDef PC13;
MyTimer_Struct_TypeDef timer2,timer3;
//PA5 LED
//PC13 Bouton
char X0,X1,Y0,Y1,Z0,Z1;
char read_DATA,read_BWR,read_PWRC;
int16_t gX,gY,gZ;
int test =0;
XYZ mesures;
int main ( void )
{
PA5.GPIO=GPIOA;
PA5.GPIO_Conf=Out_Ppull;
PA5.GPIO_Pin=5;
MyGPIO_Init(&PA5);
timer2.Timer=TIM2;
timer2.ARR=18000; //pour avoir 250ms
timer2.PSC=1000;
MyTimer_Base_Init(&timer2);
MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT);
MyTimer_Base_Start(timer2.Timer);
timer3.Timer=TIM3;
timer3.ARR=7200; //pour avoir 100ms
timer3.PSC=1000;
MyTimer_Base_Init(&timer3);
//MyTimer_ActiveIT(timer3.Timer,2, &Mafonction_IT);
MyTimer_Base_Start(timer3.Timer);
MyPWM_init(timer3.Timer,3);
MySPI_Init(SPI1);
rouli_InitAccel();
MySPI_Send(READ|DATA_FORMAT);
read_DATA = MySPI_Read();
MySPI_Send(READ|BW_RATE);
read_BWR = MySPI_Read();
MySPI_Send(READ|POWER_CTL);
read_PWRC = MySPI_Read();
while(1)
{
rouli_GetAccel(&mesures);
if(timer2.Timer->SR&=0x04)
{
if((mesures.gY <= (-0.7)) || (mesures.gY >= 0.7))
{
MyPWM_Duty(timer3.Timer,3,71);//0.985ms
test = test+1;
}
}
}
return 0;
}
void Mafonction_IT (void)
{
MyGPIO_Toggle(PA5.GPIO,5);
}