Fonction V1 de paramétrage et lecture des registre de l'accéléromètre.

This commit is contained in:
Guilhem Chambaud 2023-04-04 15:17:30 +02:00
parent e035bfb760
commit 8530d2a8a1
5 changed files with 85 additions and 18 deletions

View file

@ -1,6 +1,57 @@
#include "stm32f10x.h"
#include "accelerometer.h"
#include "MySPI.h"
#include "gpio.h"
void MySPI_Init(SPI_TypeDef *)
void accelerometre()
{
int dataX ;
float GX ;
int dataY ;
float GY;
int dataZ ;
float GZ;
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
MySPI_Clear_NSS(); //CS LOW
MySPI_Send(0xF2);
dataX = MySPI_Read()<<8;
dataX |= MySPI_Read();
dataX &= 0xE;
GX = dataX*0.004;
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
}

View file

@ -2,7 +2,7 @@
#define INC_ACCELEROMETER_H_
#include "../driver/MySPI.h"
void accelerometre();
#endif

View file

@ -1,10 +1,11 @@
#include "stm32f10x.h"
#include "../../driver/MyI2C.h"
#include "../../driver/MySPI.h"
#include "../../implementation/acceleromer.h"
#include "MyI2C.h"
#include "MySPI.h"
#include "accelerometer.h"
int main (void)
{
while(1){};
while(1){
accelerometre();};
}

View file

@ -75,7 +75,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
<IsCurrentTarget>0</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -257,7 +257,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
@ -312,7 +312,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
<Name>-U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -339,7 +339,23 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>6</LineNumber>
<LineNumber>54</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134220334</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>C:\Users\guilh\OneDrive\Bureau\COURS\INSA AE\µC S6\voilier-team-1\implementation\accelerometer.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_reel\../implementation/accelerometer.c\54</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>5</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
@ -348,7 +364,7 @@
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<Filename>..\implementation\accelerometer.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>

View file

@ -10,9 +10,8 @@
<TargetName>Simulé</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pArmCC>6190000::V6.19::ARMCLANG</pArmCC>
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
<uAC6>1</uAC6>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>STM32F103RB</Device>
@ -324,7 +323,7 @@
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>3</wLevel>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>0</uC99>
@ -474,7 +473,7 @@
<TargetName>Réel</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>