Merging from guilhem to master

This commit is contained in:
Yohan Boujon 2023-04-07 14:34:13 +02:00
commit 24cd95c9e3
4 changed files with 74 additions and 8 deletions

View file

@ -0,0 +1,57 @@
#include "stm32f10x.h"
#include "accelerometer.h"
#include "MySPI.h"
#include "gpio.h"
void accelerometre()
{
int dataX ;
float GX ;
int dataY ;
float GY;
int dataZ ;
float GZ;
char testReg;
MySPI_Init(SPI1);
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0x2D);//Registre Auto_sleep + Write + measure a 1
MySPI_Send(0x08);// désactive
MySPI_Set_NSS();//CS HIGH
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0xAD);// regisstre 0x2D en lecture
testReg = MySPI_Read(); // lecture de la valeur du registre
MySPI_Set_NSS();//CS HIGH
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0X2C);//Registre power consuption + Write
MySPI_Send(0X1A);//Paramétrage hors low consumption + 100Hz output data rate
MySPI_Set_NSS();//CS HIGH
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0x31);//registre Data format + write
MySPI_Send(0x17);//
MySPI_Set_NSS();//CS HIGH
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0xF2);
dataX = MySPI_Read()<<8;
dataX |= MySPI_Read();
dataX &= 0xE;
GX = dataX*0.004;
dataY = MySPI_Read()<<8;
dataY |= MySPI_Read();
dataY &= 0xE;
GY = dataY*0.004;
dataZ = MySPI_Read()<<8;
dataZ |= MySPI_Read();
dataZ &= 0xE;
GZ = dataZ*0.004;
MySPI_Set_NSS();//CS HIGH
}

View file

@ -0,0 +1,8 @@
#ifndef INC_ACCELEROMETER_H_
#define INC_ACCELEROMETER_H_
#include "../driver/MySPI.h"
void accelerometre();
#endif

View file

@ -8,7 +8,7 @@ void (*IT_I2C_Err) (void) = plantage_i2C;
void MyRTC_Init(void)
{
MyI2C_Init(I2C1, 15, IT_I2C_Err);
MyI2C_Init(I2C2, 15, IT_I2C_Err);
}
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year)
@ -20,18 +20,18 @@ void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* mont
data.Ptr_Data = &regCopy;
data.Nb_Data = 1;
MyI2C_GetString(I2C1, 0x00, &data);
MyI2C_GetString(I2C2, 0x00, &data);
*sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C1, 0x01, &data);
MyI2C_GetString(I2C2, 0x01, &data);
*min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C1, 0x02, &data);
MyI2C_GetString(I2C2, 0x02, &data);
*hour = 0;
MyI2C_GetString(I2C1, 0x03, &data);
MyI2C_GetString(I2C2, 0x03, &data);
*day = (regCopy & 0x07);
MyI2C_GetString(I2C1, 0x04, &data);
MyI2C_GetString(I2C2, 0x04, &data);
*date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C1, 0x05, &data);
MyI2C_GetString(I2C2, 0x05, &data);
*month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C1, 0x06, &data);
MyI2C_GetString(I2C2, 0x06, &data);
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
}

View file

@ -26,4 +26,5 @@ void initImplementation(void)
MyMotor_ChangeSpeed(0);
MyMotor_ChangeDirection(HORAIRE);
MyRTC_Init();
accelerometre();
}