📄 mma7455l_init.c
字号:
/*********************************************************************
(c) copyright Freescale Semiconductor Ltd. 2008
ALL RIGHTS RESERVED
********************************************************************
Ver 2.0.2 Released Sep.2008
********************************************************************/
#ifdef G_SENSOR_SUPPORT
#include "MMA7455L.h"
#define MMA7455L_ClearInterrupt mma745x_IICWrite(INTRST, 0x03);\
mma745x_IICWrite(INTRST, 0x00); // Clear interrupt flags
void MMA7455L_Startup(void)
{
//mma745x_IICWrite(MCTL, 0x41);
mma745x_IICWrite(MCTL, 0x45); //2g measurement mode, data ready signal not output //0x43
// b01000101
// ||||||||
// ||||||++- MODE: 00 - Standby
// |||||| 01 - Measurement
// |||||| 10 - Level Detection
// |||||| 11 - Pulse Detection
// |||||++-- GLVL: 00 - 8 G
// |||| 10 - 4 G
// |||| 01 - 2 G
// |||+----- STON: 0 - Self Test Disabled
// ||+------ SPI3W:0 - 3-wire SPI
// |+------- DRPD: 1 - Data Ready NOT Output to PIN1
// +-------- Reserved: 0
mma745x_IICWrite(CTL1, 0x00); //b00000000 //0xaa
//mma745x_IICWrite(CTL1, 0x30); //b00000000
// ||||||||
// |||||||+- INTPIN: 0 - INT pins and register bits do not swap
// |||||++-- INTREG[1:0]: 00 - INT1 for level detection, INT2 for pulse detection
// ||||+---- XDA: 0 - X axis enabled for detection
// |||+----- YDA: 0 - Y axis enabled for detection
// ||+------ ZDA: 0 - Z axis enabled for detection
// |+------- THOPT: 0 - Level detection threshold is absolute value
// +-------- DFBW: 0 - Digital filter band width is 62.5Hz
mma745x_IICWrite(CTL2, 0x00); //b00000000
// |||
// ||+- LDPL: 0 - Level detection polarity is positive
// |+-- PDPL: 0 - Pulse detection polarity is positive
// +--- DRVO: 0 - Standard drive strength on SDA/SDO pin
mma745x_IICWrite(LDTH, 0x00); // Level detection threshold //0x7f
mma745x_IICWrite(PDTH, 0x00); // Pulse detection threshold //0x4f
mma745x_IICWrite(PW, 0x00); // Pulse Duration, 0.5mS per count //0x37
mma745x_IICWrite(LT, 0x00); // Latency time, max 255mS //0x64
mma745x_IICWrite(TW, 0x00); // Time Window for 2nd Pulse, max 255mS
/*
mma745x_IICWrite(XOFFL, XoffvalueL); //Set X offset register with value from calibration
mma745x_IICWrite(XOFFH, XoffvalueH); //Set X offset register with value from calibration
mma745x_IICWrite(YOFFL, YoffvalueL); //Set Y offset register with value from calibration
mma745x_IICWrite(YOFFH, YoffvalueH); //Set Y offset register with value from calibration
mma745x_IICWrite(ZOFFL, ZoffvalueL); //Set Z offset register with value from calibration
mma745x_IICWrite(ZOFFH, ZoffvalueH); //Set Z offset register with value from calibration
*/
MMA7455L_ClearInterrupt;
}
/*
void Turn_Init_MMA7455L(void)
{
mma745x_init();
mma745x_IICWrite(0x16, 0x45); // Enable measurment mode
}
*/
void Tap_Init_MMA7455L(void)
{
//mma745x_IICWrite(MCTL, 0x47); // 2g pulse detection mode, data ready signal not output //0x47
mma745x_IICWrite(MCTL, 0x4b);
// b01000111
// ||||||||
// ||||||++- MODE: 00 - Standby
// |||||| 01 - Measurement
// |||||| 10 - Level Detection
// |||||| 11 - Pulse Detection
// |||||++-- GLVL: 00 - 8 G
// |||| 10 - 4 G
// |||| 01 - 2 G
// |||+----- STON: 0 - Self Test Disabled
// ||+------ SPI3W:0 - 3-wire SPI
// |+------- DRPD: 1 - Data Ready NOT Output to PIN1
// +-------- Reserved: 0
//mma745x_IICWrite(CTL1, 0x9A); //b00000100
//mma745x_IICWrite(CTL1, 0x04); //b00000100 GOOD
mma745x_IICWrite(CTL1, 0x1a);
// ||||||||
// |||||||+- INTPIN: 0 - INT pins and register bits do not swap
// |||||++-- INTREG[1:0]: 10 - INT1 for pulse, INT2 for pulse detection
// ||||+---- XDA: 0 - X axis enabled for detection
// |||+----- YDA: 0 - Y axis enabled for detection
// ||+------ ZDA: 0 - Z axis enabled for detection
// |+------- THOPT: 0 - Level detection threshold is absolute value
// +-------- DFBW: 0 - Digital filter band width is 62.5Hz
mma745x_IICWrite(CTL2, 0x00); //b00000000
// |||
// ||+- LDPL: 0 - Level detection polarity is positive
// |+-- PDPL: 0 - Pulse detection polarity is positive
// +--- DRVO: 0 - Standard drive strength on SDA/SDO pin
mma745x_IICWrite(LDTH, 0x7F); // Level detection threshold is maximum
//mma745x_IICWrite(LDTH, 0x3F); // Level detection threshold is maximum
//mma745x_IICWrite(PDTH, 0x30); // Pulse detection threshold is 3G
//mma745x_IICWrite(PDTH, 0x20); // Pulse detection threshold is 3G
//mma745x_IICWrite(PDTH, 0x30); // Pulse detection threshold is 3G
mma745x_IICWrite(PDTH, 0x50); // Pulse detection threshold is 3G
//mma745x_IICWrite(PW, 0x14); // Pulse Duration = 2 * 0.5mS = 1 mS
mma745x_IICWrite(PW, 0x06); // Pulse Duration = 2 * 0.5mS = 1 mS
//mma745x_IICWrite(LT, 0x50); // Latency time, max 255mS
mma745x_IICWrite(LT, 0x10); // Latency time, max 255mS
//mma745x_IICWrite(TW, 0x20); // Time Window for 2nd Pulse, max 255mS
mma745x_IICWrite(TW, 0x00); // Time Window for 2nd Pulse, max 255mS
MMA7455L_ClearInterrupt;
/*
for(ii=0;ii<22000*100;ii++)
;
GPIO_ModeSetup(3, 3); //handshake1
EINT_Registration(G_SENSOR_NO,1,0,ACCELEROMETER_EINT_HISR, 1);
EINT_Set_Sensitivity(G_SENSOR_NO,0);
EINT_Set_HW_Debounce(G_SENSOR_NO, 50);
*/
}
void MMA7455L_Standby(void)
{
mma745x_IICWrite(MCTL, 0x44); // Make MMA7455L enter standby mode
}
#endif /* G_SENSOR_SUPPORT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -