//LSM303DLH.h
/*************************************************************************************************************
* 文件名: LSM303DLH.h
* 功能: LSM303DLH驱动
* 作者: cp1300@139.com
* 创建时间: 2019-01-10
* 最后修改时间: 2019-01-10
* 详细: LSM303DLH六轴角度传感器
依赖SoftwareIIC
*************************************************************************************************************/
#ifndef _LSM303DLH_H_
#define _LSM303DLH_H_
#include "system.h"
#include "SoftwareIIC.h"
//LSM303DLH 寄存器定义
typedef enum
{
//罗盘
LSM303_CRA_REG_M_0x00 = 0x00, //RW
LSM303_CRB_REG_M_0x01 = 0x01, //RW
LSM303_MR_REG_M_0x02 = 0x02, //RW
LSM303_OUT_X_H_M_0x03 = 0x03, //R
LSM303_OUT_X_L_M_0x04 = 0x04, //R
LSM303_OUT_Y_H_M_0x05 = 0x05, //R
LSM303_OUT_Y_L_M_0x06 = 0x06, //R
LSM303_OUT_Z_H_M_0x07 = 0x07, //R
LSM303_OUT_Z_L_M_0x08 = 0x08, //R
LSM303_SR_REG_Mg_0x09 = 0x09, //R
LSM303_IRA_REG_M_0x0A = 0x0A, //R
LSM303_IRB_REG_M_0x0B = 0x0B, //R
LSM303_IRC_REG_M_0x0C = 0x0C, //R
//加速度
LSM303_CTRL_REG1_A_0x20 = 0x20, //RW
LSM303_CTRL_REG2_A_0x21 = 0x21, //RW
LSM303_CTRL_REG3_A_0x22 = 0x22, //RW
LSM303_CTRL_REG4_A_0x23 = 0x23, //RW
LSM303_CTRL_REG5_A_0x24 = 0x24, //RW
LSM303_HP_FILTER_RESET_A_0x25 = 0x25, //R
LSM303_REFERENCE_A_0x26 = 0x26, //RW
LSM303_STATUS_REG_A_0x27 = 0x27, //R
LSM303_OUT_X_L_A_0x28 = 0x28, //R
LSM303_OUT_X_H_A_0x29 = 0x29, //R
LSM303_OUT_Y_L_A_0x2A = 0x2A, //R
LSM303_OUT_Y_H_A_0x2B = 0x2B, //R
LSM303_OUT_Z_L_A_0x2C = 0x2C, //R
LSM303_OUT_Z_H_A_0x2D = 0x2D, //R
LSM303_INT1_CFG_A_0x30 = 0x30, //RW
LSM303_INT1_SOURCE_A_0x31 = 0x31, //R
LSM303_INT1_THS_A_0x32 = 0x32, //RW
LSM303_INT1_DURATION_A_0x33 = 0x33, //RW
LSM303_INT2_CFG_A_0x34 = 0x34, //RW
LSM303_INT2_SOURCE_A_0x35 = 0x35, //R
LSM303_INT2_THS_A_0x36 = 0x36, //RW
LSM303_INT2_DURATION_A_0x37 = 0x37, //RW
}LSM303DLH_REG_TYPE;
//LSM303DLH 句柄
typedef struct
{
SIIC_HANDLE IIC_Handle; //IIC接口
u8 SlaveAddr_A; //加速度传感器通讯地址
u8 SlaveAddr_M; //磁场传感器通讯地址
}LSM303DLH_HANDLE;
bool LSM303DLH_Init(LSM303DLH_HANDLE *pHandle, u8 SlaveAddr_A, u8 SlaveAddr_M); //LSM303DLH初始化
bool LSM303DLH_ReadAcceleration(LSM303DLH_HANDLE *pHandle, s16 *pXa,s16 *pYa, s16 *pZa); //LSM303DLH 读取三轴加速度
bool LSM303DLH_ReadMagnetic(LSM303DLH_HANDLE *pHandle, s16 *pXm,s16 *pYm, s16 *pZm); //LSM303DLH 读取磁场强度值
int LSM303DLH_CalculationZAxisAngle(s16 Ax, s16 Ay, s16 Az); //LSM303DLH 计算Z轴倾角(扩大100倍)
int LSM303DLH_CalculationXAxisAngle(s16 Ax, s16 Ay, s16 Az); //LSM303DLH 计算X轴倾角(扩大100倍)
#endif /*_LSM303DLH_H_*/
|