2023-04-04 15:17:30 +02:00
|
|
|
|
#include "stm32f10x.h"
|
2023-04-03 08:24:42 +02:00
|
|
|
|
#include "accelerometer.h"
|
|
|
|
|
#include "MySPI.h"
|
|
|
|
|
#include "gpio.h"
|
|
|
|
|
|
2023-04-07 15:28:30 +02:00
|
|
|
|
void accelerometre(void)
|
2023-04-04 15:17:30 +02:00
|
|
|
|
{
|
|
|
|
|
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<61>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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-07 15:28:30 +02:00
|
|
|
|
}
|