MPL3115A2 Freescale I2C圧力センサーの経験はありますか?Arduino UNO r3に関するプロジェクトで使用する必要がありますが、正しく通信できません。これが私のコードです:
#include <Wire.h>
void setup(){
Serial.begin(9600);
/*Start communication */
Wire.begin();
// Put sensor as in Standby mode
Wire.beginTransmission((byte)0x60); //0x60 is sensor address
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x00); //reset_reg
Wire.endTransmission();
delay(10);
// start sensor as Barometer Active
Wire.beginTransmission((byte)0x60);
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x01); //start sensor as barometer
Wire.endTransmission();
delay(10);
}
void getdata(byte *a, byte *b, byte *c){
Wire.beginTransmission(0x60);
Wire.write((byte)0x01); // Data_PMSB_reg address
Wire.endTransmission(); //Stop transmission
Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
while(Wire.available()==0);
*a = Wire.read(); // first received byte stored here
*b = Wire.read(); // second received byte stored here
*c = Wire.read(); // third received byte stored here
}
void loop(){
byte aa,bb,cc;
getdata(&aa,&bb,&cc);
Serial.println(aa,HEX); //print aa for example
Serial.println(bb,HEX); //print bb for example
Serial.println(cc,HEX); //print cc for example
delay(5000);
}
私が受け取るデータは次のとおりです:05FB9(たとえば)。レジスタアドレスを変更すると(を参照Wire.write((byte)0x01); // Data_PMSB_reg address
)、データが変更されることを期待していますが、変更されません。これを説明してもらえますか?ドキュメントとデータシートは、NXPのWebサイトにあります。
彼らがどのようにコミュニケーションを取っているのか、私には正しく理解できません。Arduinoと他のI2Cセンサーと同じ通信プロトコルで問題なく通信できました。