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 14:26:51 +02:00
|
|
|
|
void Init_accelerometre()
|
2023-04-04 15:17:30 +02:00
|
|
|
|
{
|
2023-04-07 14:26:51 +02:00
|
|
|
|
//char testReg;
|
2023-04-04 15:17:30 +02:00
|
|
|
|
|
|
|
|
|
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
|
2023-04-07 14:26:51 +02:00
|
|
|
|
/*
|
2023-04-04 15:17:30 +02:00
|
|
|
|
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
|
2023-04-07 14:26:51 +02:00
|
|
|
|
*/
|
2023-04-04 15:17:30 +02:00
|
|
|
|
|
|
|
|
|
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
|
2023-04-07 14:26:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 13:47:22 +02:00
|
|
|
|
void Lecture_accelerometre(float* GX, float* GY, float* GZ)
|
2023-04-07 14:26:51 +02:00
|
|
|
|
{
|
2023-04-11 13:47:22 +02:00
|
|
|
|
int16_t dataX ;
|
|
|
|
|
int16_t dataY ;
|
|
|
|
|
int16_t dataZ ;
|
2023-04-04 15:17:30 +02:00
|
|
|
|
|
|
|
|
|
MySPI_Clear_NSS(); //CS LOW
|
2023-04-07 14:26:51 +02:00
|
|
|
|
|
|
|
|
|
MySPI_Send(0xF2);//lecture 1er registre acc<63>l<EFBFBD>rom<6F>tre + lecture multibytes
|
2023-04-11 13:47:22 +02:00
|
|
|
|
dataX = MySPI_Read()<<8; // donn<6E>es sur 13 (12 data + sign) bits passage 8 bit en PF
|
2023-04-07 14:26:51 +02:00
|
|
|
|
dataX |= MySPI_Read(); //lecture SPI
|
2023-04-11 13:47:22 +02:00
|
|
|
|
dataX &= 0x1FFF; //masquage au dessus du bit 13
|
|
|
|
|
if (dataX > 511)
|
|
|
|
|
{
|
|
|
|
|
dataX -= 1024;
|
|
|
|
|
}
|
2023-04-07 14:26:51 +02:00
|
|
|
|
*GX = dataX*0.004;//valeur du registre x pas accelerometre
|
2023-04-11 13:47:22 +02:00
|
|
|
|
|
2023-04-04 15:17:30 +02:00
|
|
|
|
dataY = MySPI_Read()<<8;
|
|
|
|
|
dataY |= MySPI_Read();
|
2023-04-11 13:47:22 +02:00
|
|
|
|
dataY &= 0x1FFF;
|
|
|
|
|
if (dataY > 511)
|
|
|
|
|
{
|
|
|
|
|
dataY -= 1024;
|
|
|
|
|
}
|
|
|
|
|
*GY = dataY*0.004;//valeur du registre x pas accelerometre
|
2023-04-07 14:26:51 +02:00
|
|
|
|
|
2023-04-11 13:47:22 +02:00
|
|
|
|
dataZ = ((MySPI_Read()<<8)|MySPI_Read());
|
|
|
|
|
dataZ &= 0x1FFF;
|
|
|
|
|
/* if (dataZ > 511)
|
|
|
|
|
{
|
|
|
|
|
dataZ -= 1024;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
*GZ = dataZ*0.004;//valeur du registre x pas accelerometre
|
2023-04-04 15:17:30 +02:00
|
|
|
|
|
2023-04-07 14:26:51 +02:00
|
|
|
|
MySPI_Set_NSS();//CS HIGH
|
2023-04-04 15:17:30 +02:00
|
|
|
|
}
|