Accelerometre
This commit is contained in:
parent
0df040dc01
commit
06df73ad1a
5 changed files with 82 additions and 24 deletions
|
@ -13,8 +13,10 @@
|
|||
#define DATA_FORMAT 0x31
|
||||
#define BW_RATE 0x2C
|
||||
#define POWER_CTL 0x2D
|
||||
#define READ 0xC0
|
||||
#define WRITE 0x40
|
||||
#define READ_MB 0xC0
|
||||
#define WRITE_MB 0x40
|
||||
#define READ 0x80
|
||||
#define WRITE 0x00
|
||||
|
||||
/*************************************************************************************
|
||||
===================== By Periph team INSA GEI 2022 ===========================
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
#include "stm32f10x.h"
|
||||
typedef struct
|
||||
{
|
||||
float gX;
|
||||
float gY;
|
||||
float gZ;
|
||||
|
||||
}XYZ;
|
||||
|
||||
void rouli_InitAccel(void);
|
||||
|
||||
char roulis (void);
|
||||
void rouli_GetAccel (XYZ * axe);
|
||||
|
||||
void rouli_IT_Bascule(void);
|
||||
|
|
|
@ -2,29 +2,45 @@
|
|||
#include "GPIO.h"
|
||||
#include "TIMER.h"
|
||||
#include "MySPI.h"
|
||||
#include "Rouli.h"
|
||||
|
||||
|
||||
|
||||
char accelerometre = 0 ;
|
||||
/* Dans cette partie nous allons traiter le roulis du voiluier */
|
||||
char roulis (void)
|
||||
{
|
||||
|
||||
|
||||
|
||||
void rouli_InitAccel(void)
|
||||
{
|
||||
MySPI_Clear_NSS();
|
||||
/* Init de l'accelerometre avec SPI */
|
||||
/* Init de l'accelerometre avec SPI */
|
||||
MySPI_Send(WRITE|DATA_FORMAT); /* Ecriture dans le data Format */
|
||||
MySPI_Send(0x8B); /* Envoi des paramètres */
|
||||
MySPI_Send(0x0B); /* Envoi des paramètres */
|
||||
MySPI_Send(WRITE|BW_RATE); /* Ecriture dans le BW rate */
|
||||
MySPI_Send(0x0A); /* Envoi des paramètres */
|
||||
MySPI_Send(WRITE|POWER_CTL); /* Ecriture dans le POWER_CTL */
|
||||
MySPI_Send(0x08); /* Envoi des paramètre */
|
||||
MySPI_Send(READ|DATAX0);
|
||||
|
||||
|
||||
|
||||
accelerometre = MySPI_Read () ;
|
||||
|
||||
|
||||
return accelerometre ;
|
||||
|
||||
MySPI_Set_NSS();
|
||||
}
|
||||
|
||||
|
||||
void rouli_GetAccel (XYZ * axe)
|
||||
{
|
||||
char X0,X1,Y0,Y1,Z0,Z1;
|
||||
|
||||
MySPI_Clear_NSS();
|
||||
|
||||
MySPI_Send(READ_MB|DATAX0);
|
||||
|
||||
X0 = MySPI_Read () ;
|
||||
X1 = MySPI_Read () ;
|
||||
Y0 = MySPI_Read () ;
|
||||
Y1 = MySPI_Read () ;
|
||||
Z0 = MySPI_Read () ;
|
||||
Z1 = MySPI_Read () ;
|
||||
MySPI_Set_NSS();
|
||||
|
||||
axe->gX = ((short int)((X1<<8)|X0))*0.004;
|
||||
axe->gY = ((short int)((Y1<<8)|Y0))*0.004;
|
||||
axe->gZ = ((short int)((Z1<<8)|Z0))*0.004;
|
||||
}
|
||||
|
||||
// axe y entre -0.5 et 1
|
|
@ -4,6 +4,7 @@
|
|||
#include "MyI2C.h"
|
||||
#include "MySPI.h"
|
||||
#include "Rouli.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void Mafonction_IT (void);
|
||||
|
@ -12,10 +13,15 @@ MyGPIO_Struct_TypeDef PC13;
|
|||
MyTimer_Struct_TypeDef timer2;
|
||||
//PA5 LED
|
||||
//PC13 Bouton
|
||||
char accel;
|
||||
char X0,X1,Y0,Y1,Z0,Z1;
|
||||
char read_DATA,read_BWR,read_PWRC;
|
||||
int16_t gX,gY,gZ;
|
||||
|
||||
XYZ mesures;
|
||||
|
||||
int main ( void )
|
||||
{
|
||||
|
||||
PA5.GPIO=GPIOA;
|
||||
PA5.GPIO_Conf=Out_Ppull;
|
||||
PA5.GPIO_Pin=5;
|
||||
|
@ -28,11 +34,20 @@ int main ( void )
|
|||
MyTimer_Base_Start(timer2.Timer);
|
||||
|
||||
MySPI_Init(SPI1);
|
||||
rouli_InitAccel();
|
||||
MySPI_Send(READ|DATA_FORMAT);
|
||||
read_DATA = MySPI_Read();
|
||||
MySPI_Send(READ|BW_RATE);
|
||||
read_BWR = MySPI_Read();
|
||||
MySPI_Send(READ|POWER_CTL);
|
||||
read_PWRC = MySPI_Read();
|
||||
|
||||
while(1)
|
||||
{
|
||||
accel = roulis();
|
||||
rouli_GetAccel(&mesures);
|
||||
//printf("%f, %f, %f\n",mesures.gX,mesures.gY,mesures.gZ);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=318,388,739,793,0)(121=1101,403,1522,808,0)(122=1281,393,1702,798,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1190,328,1611,733,1)(121=1101,403,1522,808,0)(122=1281,393,1702,798,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -336,6 +336,21 @@
|
|||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>mesures</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
<WinNumber>1</WinNumber>
|
||||
<SubType>0</SubType>
|
||||
<ItemText>0x20000018</ItemText>
|
||||
<AccSizeX>0</AccSizeX>
|
||||
</Mm>
|
||||
</MemoryWindow1>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
@ -458,7 +473,7 @@
|
|||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Rouli.c</PathWithFileName>
|
||||
|
|
Loading…
Reference in a new issue