Accelerometer library finished with 2 functions 1 for Init and 1 for data reading.

This commit is contained in:
Guilhem Chambaud 2023-04-07 14:26:51 +02:00
parent 8530d2a8a1
commit 51aa50f505
4 changed files with 31 additions and 43 deletions

View file

@ -3,28 +3,22 @@
#include "MySPI.h" #include "MySPI.h"
#include "gpio.h" #include "gpio.h"
void accelerometre() void Init_accelerometre()
{ {
int dataX ; //char testReg;
float GX ;
int dataY ;
float GY;
int dataZ ;
float GZ;
char testReg;
MySPI_Init(SPI1); MySPI_Init(SPI1);
MySPI_Clear_NSS(); //CS LOW MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0x2D);//Registre Auto_sleep + Write + measure a 1 MySPI_Send(0x2D);//Registre Auto_sleep + Write + measure a 1
MySPI_Send(0x08);// désactive MySPI_Send(0x08);// désactive
MySPI_Set_NSS();//CS HIGH MySPI_Set_NSS();//CS HIGH
/*
MySPI_Clear_NSS(); //CS LOW MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0xAD);// regisstre 0x2D en lecture MySPI_Send(0xAD);// regisstre 0x2D en lecture
testReg = MySPI_Read(); // lecture de la valeur du registre testReg = MySPI_Read(); // lecture de la valeur du registre
MySPI_Set_NSS();//CS HIGH MySPI_Set_NSS();//CS HIGH
*/
MySPI_Clear_NSS(); //CS LOW MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0X2C);//Registre power consuption + Write MySPI_Send(0X2C);//Registre power consuption + Write
@ -35,23 +29,31 @@ void accelerometre()
MySPI_Send(0x31);//registre Data format + write MySPI_Send(0x31);//registre Data format + write
MySPI_Send(0x17);// MySPI_Send(0x17);//
MySPI_Set_NSS();//CS HIGH 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_Clear_NSS(); //CS LOW
MySPI_Send(0xF2);
dataX = MySPI_Read()<<8; MySPI_Send(0xF2);//lecture 1er registre accéléromètre + lecture multibytes
dataX |= MySPI_Read(); dataX = MySPI_Read()<<8; // données sur 13 bits passage 8 bit en PF
dataX &= 0xE; dataX |= MySPI_Read(); //lecture SPI
GX = dataX*0.004; 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()<<8;
dataY |= MySPI_Read(); dataY |= MySPI_Read();
dataY &= 0xE; dataY &= 0xE;
GY = dataY*0.004; *GY = dataY*0.004;
dataZ = MySPI_Read()<<8; dataZ = MySPI_Read()<<8;
dataZ |= MySPI_Read(); dataZ |= MySPI_Read();
dataZ &= 0xE; dataZ &= 0xE;
GZ = dataZ*0.004; *GZ = dataZ*0.004;
MySPI_Set_NSS();//CS HIGH MySPI_Set_NSS();//CS HIGH
} }

View file

@ -2,7 +2,7 @@
#define INC_ACCELEROMETER_H_ #define INC_ACCELEROMETER_H_
#include "../driver/MySPI.h" #include "../driver/MySPI.h"
void accelerometre(); void Init_accelerometre();
void Lecture_accelerometre(float *GX, float* GY, float* GZ);
#endif #endif

View file

@ -3,9 +3,11 @@
#include "MySPI.h" #include "MySPI.h"
#include "accelerometer.h" #include "accelerometer.h"
float GX, GY, GZ;
int main (void) int main (void)
{ {
Init_accelerometre();
while(1){ while(1){
accelerometre();}; Lecture_accelerometre(&GX,&GY,&GZ);
};
} }

View file

@ -339,9 +339,9 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>54</LineNumber> <LineNumber>58</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>134220334</Address> <Address>134219020</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
@ -350,23 +350,7 @@
<BreakIfRCount>1</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>C:\Users\guilh\OneDrive\Bureau\COURS\INSA AE\µC S6\voilier-team-1\implementation\accelerometer.c</Filename> <Filename>C:\Users\guilh\OneDrive\Bureau\COURS\INSA AE\µC S6\voilier-team-1\implementation\accelerometer.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression>\\cool_reel\../implementation/accelerometer.c\54</Expression> <Expression>\\cool_reel\../implementation/accelerometer.c\58</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>5</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\implementation\accelerometer.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp> </Bp>
</Breakpoint> </Breakpoint>
<WatchWindow1> <WatchWindow1>