1、Arduino/maple 驱动 MMA7660 例程2011-07-30 10:15Arduino/maple 驱动 MMA7660 例程【整理者】【提供者】yuyyy【详细说明】Arduino/maple 驱动 MMA7660 例程我们是深圳本土最受客户青睐、成长最快、最关注增值服务的 MID 电子元件提供商之一。我们深圳的长期大量现货型号有:MMA7660, MMA7455, MMA8452QR1, MXC6225XU, MMC3140MS, TS1003,MPU-3050, ALC5621, ALC5625, WM8988, ES8388,联系热线:13714686590,杨先生/SD
2、A (data line) is on pin 30, and SCL (clock line) is on pin 29#include #define I2C_ADDRESS 0x4C#define I2C_ADDRESS_W 0x99 /MMA7660 Address + 1 bit (Write) pag. 21#define I2C_ADDRESS_R 0x98 /MMA7660 Address + 0 bit (Read) pag 21#define TILT_STATUS 0x03#define SRST 0x04#define SPCNT 0x05#define INTSU 0
3、x06#define MODE 0x07#define SR 0x08#define PDET 0x09#define PD 0x0A#define POWER_UP_DELAY 10#define X_OUT 0x00#define Y_OUT 0x01#define Z_OUT 0x02void setup()SerialUSB.println(“Setting up I2C protocol.“);Wire.begin(30,29);SLAVE_I2C_INIT();pinMode(13, OUTPUT);void loop()char x = SLAVE_I2C_READ(X_OUT)
4、;char y = SLAVE_I2C_READ(Y_OUT);char z = SLAVE_I2C_READ(Z_OUT);char mode = SLAVE_I2C_READ(0x07);/ char tilt = SLAVE_I2C_READ(0x03);char sample = SLAVE_I2C_READ(0x04);/ char fac = SLAVE_I2C_READ(0x0B);SerialUSB.print(“X=“);SerialUSB.print(x, DEC);SerialUSB.print(“, Y=“);SerialUSB.print(y, DEC);Serial
5、USB.print(“, Z=“);SerialUSB.print(z, DEC);SerialUSB.print(“, Mode=“);SerialUSB.print(mode,DEC);/Serial.print(“, Tilt=“);/ Serial.print(tilt,DEC);SerialUSB.print(“, sample=“);SerialUSB.print(sample,DEC);/Serial.print(“, fac=“);/Serial.print(fac,DEC);SerialUSB.println(“.“);delay(100);void SLAVE_I2C_IN
6、IT()SerialUSB.println(“Powering up SLAVE interface.“);delay(POWER_UP_DELAY);SLAVE_I2C_SEND(MODE,0x00); / Setting up MODE to Stand by to set SRdelay(100);SLAVE_I2C_SEND(SR,0x00); / Setting up SR register to 120 samples active and auto sleep modedelay(100);SLAVE_I2C_SEND(MODE,0x01); /Setting up MODE A
7、ctive to START measuresdelay(100);void SLAVE_I2C_SEND(unsigned char REG_ADDRESS, unsigned char DATA) /SEND data to MMA7660Wire.beginTransmission(I2C_ADDRESS);Wire.send(REG_ADDRESS);Wire.send(DATA);Wire.endTransmission();unsigned char SLAVE_I2C_READ(unsigned char REG_ADDRESS) /READ MMA7660 dataunsign
8、ed char R_VALUE;Wire.beginTransmission(I2C_ADDRESS);Wire.send(REG_ADDRESS); / register to readWire.endTransmission();Wire.requestFrom(I2C_ADDRESS, 1); / read a bytewhile(!Wire.available()digitalWrite(13, HIGH);delay(100);digitalWrite(13, LOW);delay(100);R_VALUE = Wire.receive();return R_VALUE;链接地址 http:/