Pergunta

Does anyone have experience with the MPL3115A2 Freescale I2C pressure sensor? I need to use it in a project concerning Arduino UNO r3, but I can't get communication between them correctly. Here is my code:

    #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);
}

The data I receive is : 05FB9 (for example). When I change the register address (see Wire.write((byte)0x01); // Data_PMSB_reg address), I expect the data to change, but it doesn't! Can you explain this to me? You can find the documentation and datasheets on the NXP website.

I can't properly understand how they communicate with each other. I got communication between Arduino and some other I2C sensors with same communication protocol without any problem.

Foi útil?

Solução

Your problem is likely due to the fact that the Freescale part requires Repeated-Start I2C communication to do reads. The original Arduino two-wire library (TWI library used by Wire), did not support Repeated-Start.

I know this because I had to rewrite TWI for one of my projects to support Repeated-Start (interrupt driven, both Master and Slave). Unfortunately I've never gotten around to uploading my code, but someone else did essentially the same thing here (at least for Master which is what you need): http://dsscircuits.com/articles/arduino-i2c-master-library.html

Lose the Wire library and use their I2C library instead.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top