ADXL345加速度传感器实现的计步器算法

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

E:\PiBits-master\MPU6050-Pi-Demo\pdm1.cPage100001:00001:/**************************************************************************//**/**************************************************************************//**00002:00002:*@file*@file00003:00003:*@briefpedometerdemoforEFM32WG_STK3800developmentkit*@briefpedometerdemoforEFM32WG_STK3800developmentkit00004:00004:************************************************************************************************************************************************************00005:00005:**00006:00006:*ThisfileislicensedundertheApacheLicenseAgreement.Seethefile*ThisfileislicensedundertheApacheLicenseAgreement.Seethefile00007:00007:*LICENSEfordetails.*LICENSEfordetails.00008:00008:**00009:00009:******************************************************************************/******************************************************************************/00010:00010:00011:00011:#include#includestdint.h00012:00012:#include#includestdbool.h00013:00013:#include#includestddef.h00014:00014:#include#includemath.h00015:00015:#include#includeem_device.h00016:00016:#include#includeem_chip.h00017:00017:#include#includeem_cmu.h00018:00018:#include#includeem_emu.h00019:00019:#include#includeem_gpio.h00020:00020:#include#includei2cspm.h00021:00021:#include#includebsp.h00022:00022:#include#includesegmentlcd.h00023:00023:#include#includebsp_trace.h00024:00024:#include#includeudelay.h00025:00025:00026:00026:/**Driverhandleinstances*//**Driverhandleinstances*/00027:00027:I2CSPM_Init_TypeDefI2CSPM_Init_TypeDefADXL345HandleADXL345Handle==I2CSPM_INIT_DEFAULTI2CSPM_INIT_DEFAULT;;00028:00028:#define#defineADXL345I2CADDRADXL345I2CADDR0xA60xA600028:00028://定义器件在IIC总线中的从地址,根据ALTADDRESS地址引脚不同修改//定义器件在IIC总线中的从地址,根据ALTADDRESS地址引脚不同修改00029:00029://ALTADDRESS引脚接地时地址为0xA6,接电源时地址为0x3A//ALTADDRESS引脚接地时地址为0xA6,接电源时地址为0x3A00030:00030:#define#defineDEVICEID_REG_ADDRDEVICEID_REG_ADDR0x000x0000031:00031:#define#defineDATA_START_REG_ADDRDATA_START_REG_ADDR0x320x3200032:00032:#define#defineDATA_STOP_REG_ADDRDATA_STOP_REG_ADDR0x370x3700033:00033:#define#defineFIFO_CTL_REG_ADDRFIFO_CTL_REG_ADDR0x380x3800034:00034:#define#defineFIFO_STA_REG_ADDRFIFO_STA_REG_ADDR0x390x3900035:00035:00036:00036:#define#defineADXL345_I2C_SCL_PORTADXL345_I2C_SCL_PORTgpioPortCgpioPortC00037:00037:#define#defineADXL345_I2C_SCL_PINADXL345_I2C_SCL_PIN5500038:00038:#define#defineADXL345_I2C_SDA_PORTADXL345_I2C_SDA_PORTgpioPortCgpioPortC00039:00039:#define#defineADXL345_I2C_SDA_PINADXL345_I2C_SDA_PIN4400040:00040:#define#defineADXL345_I2C_PORT_LOCADXL345_I2C_PORT_LOC0000041:00041:00042:00042://defineADXL345datastructure//defineADXL345datastructure00043:00043:typedeftypedefstructstruct00044:00044:{{00045:00045:floatfloatXX;;00046:00046:floatfloatYY;;00047:00047:floatfloatZZ;;00048:00048:00049:00049:}}SENSOR_DATA_TypeDefSENSOR_DATA_TypeDef;;00050:00050:00051:00051://Stepcountdefinitions//Stepcountdefinitions00052:00052:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefTHRESHTHRESH=={{3535,,225225,,225225};};00053:00053:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefMAX_DATAMAX_DATA=={{00,,00,,00};};00054:00054:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefMIN_DATAMIN_DATA=={{10001000,,10001000,,10001000};};00055:00055:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefDELTADELTA=={{10001000,,10001000,,10001000};};00055:00055://max-mintoselectmostactiveaxis//max-mintoselectmostactiveaxis00056:00056:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefRESRES=={{10001000,,10001000,,10001000};};00057:00057:00058:00058:00059:00059:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefg_last_sampleg_last_sample=={{00,,00,,00};};00060:00060:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefg_cur_sampleg_cur_sample=={{00,,00,,00};};00061:00061:00062:00062:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefAVERAGE_DATAAVERAGE_DATA[[44]]=={{{{00,,00,,00},{},{00,,00,,00},{},{00,,00,,00},{},{00,,00,,00}};}};00063:00063:00064:00064:intintg_step_countg_step_count==00;;//记步数//记步数00065:00065:00066:00066:#define#definemaxmax((aa,,bb))((((aa))((bb))??((aa))::((bb))))00067:00067:00068:00068:volatilevolatileuint32_tuint32_tmsTicksmsTicks;;/*counts1mstimeTicks*//*counts1mstimeTicks*/00069:00069:00070:00070:E:\PiBits-master\MPU6050-Pi-Demo\pdm1.cPage200071:00071:00072:00072:00073:00073:staticstaticint32_tint32_tADXL345_Read_RegADXL345_Read_Reg((I2C_TypeDefI2C_TypeDef**i2ci2c,,uint8_tuint8_treg_addrreg_addr,,uint8_tuint8_t**datadata,,00073:00073:uint32_tuint32_tlenlen););00074:00074:staticstaticint32_tint32_tADXL345_Single_Write_RegADXL345_Single_Write_Reg((I2C_TypeDefI2C_TypeDef**i2ci2c,,uint8_tuint8_treg_addrreg_addr,,uint8_tuint8_t00074:00074:datadata););00075:00075:voidvoidADXL345_INITADXL345_INIT((I2C_TypeDefI2C_TypeDef**i2ci2c););00076:00076:voidvoidADXL345_CALIBRATEADXL345_CALIBRATE((I2C_TypeDefI2C_TypeDef**i2ci2c););00077:00077:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefADXL345_DATA_CONVERTADXL345_DATA_CONVERT((uint16_tuint16_t**datadata););00078:00078:SENSOR_DATA_TypeDefSENSOR_DATA_TypeDefADXL345_ADDADXL345_ADD((SENSOR_DATA_TypeDefSENSOR_DATA_TypeD

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功