收藏 分销(赏)

Arduinomaple驱动MMA7660例程.doc

上传人:xrp****65 文档编号:7725173 上传时间:2025-01-14 格式:DOC 页数:3 大小:29.50KB 下载积分:10 金币
下载 相关 举报
Arduinomaple驱动MMA7660例程.doc_第1页
第1页 / 共3页
Arduinomaple驱动MMA7660例程.doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
Arduino/maple驱动MMA7660例程 2011-07-30 10:15 Arduino/maple驱动MMA7660例程 【整理者】 【提供者】yuyyy 【详细说明】Arduino/maple驱动MMA7660例程 我们是深圳本土最受客户青睐、成长最快、最关注增值服务的MID电子元件提供商之一。我们深圳的长期大量现货型号有:MMA7660, MMA7455, MMA8452QR1, MXC6225XU, MMC3140MS, TS1003,MPU-3050, ALC5621, ALC5625, WM8988, ES8388,联系热线:13714686590,杨先生 //SDA (data line) is on  pin 30, and SCL (clock line) is on  pin 29 #include <Wire.h> #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 0x06 #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 0x02 void 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);   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);   SerialUSB.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_INIT() {   SerialUSB.println("Powering up SLAVE interface...");   delay(POWER_UP_DELAY);   SLAVE_I2C_SEND(MODE,0x00); // Setting up MODE to Stand by to set SR   delay(100);   SLAVE_I2C_SEND(SR,0x00);  // Setting up SR register to 120 samples active and auto sleep mode   delay(100);   SLAVE_I2C_SEND(MODE,0x01); //Setting up MODE Active to START measures   delay(100); } void SLAVE_I2C_SEND(unsigned char REG_ADDRESS, unsigned  char DATA)  //SEND data to MMA7660 {   Wire.beginTransmission(I2C_ADDRESS);   Wire.send(REG_ADDRESS);   Wire.send(DATA);   Wire.endTransmission(); } unsigned char SLAVE_I2C_READ(unsigned char REG_ADDRESS) //READ MMA7660 data {   unsigned char R_VALUE;   Wire.beginTransmission(I2C_ADDRESS);   Wire.send(REG_ADDRESS);  // register to read   Wire.endTransmission();   Wire.requestFrom(I2C_ADDRESS, 1); // read a byte   while(!Wire.available())   {     digitalWrite(13, HIGH);     delay(100);     digitalWrite(13, LOW);     delay(100);   }   R_VALUE = Wire.receive();   return R_VALUE;  链接地址
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服