mirror of
https://git.etud.insa-toulouse.fr/boujon/voilier-team-1.git
synced 2025-06-08 16:00:49 +02:00
acceleromètre avec valeurs en +-12G sur l'axe Z
This commit is contained in:
parent
51aa50f505
commit
c2a78c3a95
1 changed files with 25 additions and 13 deletions
|
@ -31,29 +31,41 @@ void Init_accelerometre()
|
||||||
MySPI_Set_NSS();//CS HIGH
|
MySPI_Set_NSS();//CS HIGH
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lecture_accelerometre(float *GX, float* GY, float* GZ)
|
void Lecture_accelerometre(float* GX, float* GY, float* GZ)
|
||||||
{
|
{
|
||||||
int dataX ;
|
int16_t dataX ;
|
||||||
int dataY ;
|
int16_t dataY ;
|
||||||
int dataZ ;
|
int16_t dataZ ;
|
||||||
|
|
||||||
MySPI_Clear_NSS(); //CS LOW
|
MySPI_Clear_NSS(); //CS LOW
|
||||||
|
|
||||||
MySPI_Send(0xF2);//lecture 1er registre accéléromètre + lecture multibytes
|
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()<<8; // données sur 13 (12 data + sign) bits passage 8 bit en PF
|
||||||
dataX |= MySPI_Read(); //lecture SPI
|
dataX |= MySPI_Read(); //lecture SPI
|
||||||
dataX &= 0xE; //masquage au dessus du bit 13
|
dataX &= 0x1FFF; //masquage au dessus du bit 13
|
||||||
|
if (dataX > 511)
|
||||||
|
{
|
||||||
|
dataX -= 1024;
|
||||||
|
}
|
||||||
*GX = dataX*0.004;//valeur du registre x pas accelerometre
|
*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)
|
||||||
|
{
|
||||||
|
dataY -= 1024;
|
||||||
|
}
|
||||||
|
*GY = dataY*0.004;//valeur du registre x pas accelerometre
|
||||||
|
|
||||||
dataZ = MySPI_Read()<<8;
|
dataZ = ((MySPI_Read()<<8)|MySPI_Read());
|
||||||
dataZ |= MySPI_Read();
|
dataZ &= 0x1FFF;
|
||||||
dataZ &= 0xE;
|
/* if (dataZ > 511)
|
||||||
*GZ = dataZ*0.004;
|
{
|
||||||
|
dataZ -= 1024;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
*GZ = dataZ*0.004;//valeur du registre x pas accelerometre
|
||||||
|
|
||||||
MySPI_Set_NSS();//CS HIGH
|
MySPI_Set_NSS();//CS HIGH
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue