Merge branch 'guilhem'
This commit is contained in:
commit
9d6c764ca5
3 changed files with 48 additions and 28 deletions
|
@ -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,43 @@ 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)
|
||||||
|
{
|
||||||
|
int16_t dataX ;
|
||||||
|
int16_t dataY ;
|
||||||
|
int16_t 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 (12 data + sign) bits passage 8 bit en PF
|
||||||
dataX &= 0xE;
|
dataX |= MySPI_Read(); //lecture SPI
|
||||||
GX = dataX*0.004;
|
dataX &= 0x1FFF; //masquage au dessus du bit 13
|
||||||
|
if (dataX > 511)
|
||||||
|
{
|
||||||
|
dataX -= 1024;
|
||||||
|
}
|
||||||
|
*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 &= 0x1FFF;
|
||||||
GY = dataY*0.004;
|
if (dataY > 511)
|
||||||
dataZ = MySPI_Read()<<8;
|
{
|
||||||
dataZ |= MySPI_Read();
|
dataY -= 1024;
|
||||||
dataZ &= 0xE;
|
}
|
||||||
GZ = dataZ*0.004;
|
*GY = dataY*0.004;//valeur du registre x pas accelerometre
|
||||||
|
|
||||||
|
dataZ = ((MySPI_Read()<<8)|MySPI_Read());
|
||||||
|
dataZ &= 0x1FFF;
|
||||||
|
/* if (dataZ > 511)
|
||||||
|
{
|
||||||
|
dataZ -= 1024;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
*GZ = dataZ*0.004;//valeur du registre x pas accelerometre
|
||||||
|
|
||||||
MySPI_Set_NSS();//CS HIGH
|
MySPI_Set_NSS();//CS HIGH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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
|
|
@ -4,16 +4,21 @@
|
||||||
#include "motoreducteur.h"
|
#include "motoreducteur.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
#include "accelerometer.h"
|
||||||
|
|
||||||
void initImplementation(void);
|
void initImplementation(void);
|
||||||
|
|
||||||
|
float GX, GY, GZ;
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
//MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
|
//MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
|
||||||
//MyGPIO_Init(&led); //test des leds pour ignorer les contraintes liées aux différents ports
|
//MyGPIO_Init(&led); //test des leds pour ignorer les contraintes li<EFBFBD>es aux diff<66>rents ports
|
||||||
initImplementation();
|
initImplementation();
|
||||||
//MyRTC_GetTime(&sec, &min, &hour, &day, &date, &month, &year);
|
//MyRTC_GetTime(&sec, &min, &hour, &day, &date, &month, &year);
|
||||||
while(1){};
|
while(1){
|
||||||
|
Lecture_accelerometre(&GX,&GY,&GZ);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void initImplementation(void)
|
void initImplementation(void)
|
||||||
|
@ -21,6 +26,7 @@ void initImplementation(void)
|
||||||
MyServo_Init();
|
MyServo_Init();
|
||||||
MyServo_ChangeAngle(179);
|
MyServo_ChangeAngle(179);
|
||||||
initRemote();
|
initRemote();
|
||||||
|
Init_accelerometre();
|
||||||
testRemote();
|
testRemote();
|
||||||
MyMotor_Init();
|
MyMotor_Init();
|
||||||
MyMotor_ChangeSpeed(0);
|
MyMotor_ChangeSpeed(0);
|
||||||
|
|
Loading…
Reference in a new issue