59 lines
No EOL
1.4 KiB
C
59 lines
No EOL
1.4 KiB
C
#include "stm32f10x.h"
|
|
#include "accelerometer.h"
|
|
#include "MySPI.h"
|
|
#include "gpio.h"
|
|
|
|
void Init_accelerometre()
|
|
{
|
|
//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
|
|
}
|
|
|
|
void Lecture_accelerometre(float *GX, float* GY, float* GZ)
|
|
{
|
|
int dataX ;
|
|
int dataY ;
|
|
int dataZ ;
|
|
|
|
MySPI_Clear_NSS(); //CS LOW
|
|
|
|
MySPI_Send(0xF2);//lecture 1er registre accéléromètre + lecture multibytes
|
|
dataX = MySPI_Read()<<8; // données sur 13 bits passage 8 bit en PF
|
|
dataX |= MySPI_Read(); //lecture SPI
|
|
dataX &= 0xE; //masquage au dessus du bit 13
|
|
*GX = dataX*0.004;//valeur du registre x pas accelerometre
|
|
|
|
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
|
|
} |