1、G-Sensor 8452驱动 我们深圳的长期大量现货型号有: MMA7660, MMA7455, MMA8452QR1, MXC6225XU, MMC3140MS, TS1003我们提供专业的传感器服务,联系热线: 13714686590QQ 564582990 联系人:杨先生8452是一款 G-Sensor芯片,采用 I2C跟主芯片通讯,采用中断方式跟操作系统协作。通过内部检测 XYZ三个方向的加速度,实现各种应用。原理框图如下:现在来实现在 WINCE中的 I2C驱动,读写的时序波形图分别如下:读:写:基础写函数实现如下:static P_XLLP_OST_T ost_reg = 0;s
2、tatic XLLP_I2C_T *i2c_reg = NULL;static XLLP_CLKMGR_T *clk_reg = NULL; /在初始化中要映射static int OS_I2CMasterWriteData(XLLP_UINT8_T slaveAddr, const XLLP_UINT8_T * bytesBuf, int bytesCount)volatile int status;XLLP_BOOL_T bSENDSTOP = XLLP_TRUE; /写完之后发停止位status = XllpCustomI2CWrite(P_XLLP_I2C_T)(i2c_reg), (
3、P_XLLP_OST_T)(ost_reg), slaveAddr, bytesBuf, bytesCount, bSENDSTOP,25);return status;static int MMA8452_WriteSensorReg( const XLLP_UINT8_T subAddress, XLLP_UINT8_T *bufP )XLLP_UINT8_T buffer2;int status;int lock;buffer0 = subAddress;buffer1 = *bufP;gSensorSlaveAddr = 0x1c; /I2C地址lock = _i2c_acquire_
4、lock();status = OS_I2CMasterWriteData( gSensorSlaveAddr, buffer, 2);if (XLLP_STATUS_SUCCESS != status) RETAILMSG(1, (TEXT(“Failed to write MMA8452_WriteSensorReg.rn“);_i2c_release_lock(lock);return status;基础读函数实现如下:static int OS_I2CMasterWriteData_Read(XLLP_UINT8_T slaveAddr, const XLLP_UINT8_T * by
5、tesBuf, int bytesCount)volatile int status;XLLP_BOOL_T bSENDSTOP = XLLP_FALSE; /写完后不发停止位status = XllpCustomI2CWrite(P_XLLP_I2C_T)(i2c_reg), (P_XLLP_OST_T)(ost_reg), slaveAddr, bytesBuf, bytesCount, bSENDSTOP,25);return status;static int OS_I2CMasterReadData(XLLP_UINT8_T slaveAddr, XLLP_UINT8_T * byt
6、esBuf, int bufLen)volatile int status;XLLP_BOOL_T bSENDSTOP = XLLP_TRUE; /读完后发停止位status = XllpCustomI2CRead(P_XLLP_I2C_T)(i2c_reg), (P_XLLP_OST_T)(ost_reg), slaveAddr, bytesBuf, bufLen, bSENDSTOP,25);return status;static int MMA8452_ReadSensorReg( const XLLP_UINT8_T subAddress, XLLP_UINT8_T *bufP )X
7、LLP_UINT8_T buffer1;int status;int lock;buffer0 = subAddress;*bufP = 0x00;gSensorSlaveAddr = 0x1c;lock = _i2c_acquire_lock(); status = OS_I2CMasterWriteData_For_Read( gSensorSlaveAddr, buffer, 1); /写要读的子地址,注意没有停止位if (XLLP_STATUS_SUCCESS = status)status = OS_I2CMasterReadData( gSensorSlaveAddr, buffe
8、r, 1); /重写器件地址并读*bufP = buffer0; /回传数据elseRETAILMSG(1, (TEXT(“Failed to MMA8452_ReadSensorReg.rn“);if (XLLP_STATUS_SUCCESS != status) RETAILMSG(1, (TEXT(“Failed to MMA8452_ReadSensorReg.rn“);_i2c_release_lock(lock);return status;在实际使用中,会用到 g-sensor唤醒系统。一般有方向唤醒和点击唤醒两种。两者都是利用 XYZ方向轴上的加速度变化,来中断操作系统。在配置
9、睡眠唤醒的时候,一般有若干参数寄存器需要设置合适值。其中,双击唤醒的图示如下:对于 8452,MMA8452_PULSE_THSX、MMA8452_PULSE_THSY、MMA8452_PULSE_THSZ这三个寄存器是用来设置加速度门限,值越大,需要敲击的力度也越大,对唤醒反应越迟钝。MMA8452_PULSE_TMLT 是对第一次敲击的响应时间;MMA8452_PULSE_LTCY是第一次敲击后滤波去噪的延迟时间,该参数太小,会造成有可能把第一次敲击的杂波当作第二次敲击,该参数太大,会造成相隔很短的第二次敲击不会被识别;MMA8452_PULSE_WIND 则是第二次敲击的识别时间区间,不在这个时间区间内的敲击不会被识别,以免造成误操作。