Panda 2 - MPL115A1 Pressure Sensor and SPI

Well spotted Architect :slight_smile: Thanks for your perseverance all.

I still dont have what I expect. I am expecting some sort of value back from PRESH the hardcoded value. I might have to convert it etc… but all I get is system.byte for the result field or 255 for result[0]

When I looked at the an3785.pdf sheet
I found this

[quote]Table 3. Example SPI Read Commands
Command 8-bit Code Mode Bus Type
Read Pressure Hi byte 1000000X All SPI
Read Pressure Lo byte 1000001X All SPI
Read Temperature Hi byte 1000010X All SPI
Read Temperature Lo byte 1000011X All SPI
Read Coefficient data byte 1 1000100X All SPI[/quote]

This is different to the the code I have of(i think):

  //write to start pressure sensor
            //writeRegister(0x24, 0x00);
            sendWrite1[0] = (byte)(0x24 & MPL115A1_WRITE_MASK);
            sendWrite2[0] = (0x00);

I suppose I can check the wires etc… but I have no idea how to debug this apart from that.

Should there be a connection as a first step so I can check that I have got a connection going?

On further digging I get this:

PRESH = 255
PRESL = 255
TEMPH = 255
TEMPL = 190
End of Main[/quote]

Its different almost everytime but different in completely the way I would expect. I havent yet worked out what these bytes will turn in to in the way of KPa or something. I would have that the values would have stayed fairly similar within 15-20 secs.

Write on that sensor is different then read. You have write 2 bytes in one call, that is why in my version of your code I have used byte array with the size of 2. You read one byte at a time.

Double check SPI configuration parameters (clock speed,etc.)with the datasheet.

Sorry - I didn’t spot that byte change. I shall give that a go and report back. Hopefully it will all be wonderful.

I will check the datasheet again for the SPI stuff.


No problem. Btw after you done reading individual bytes for a measurement you can assemble the value by:


//read high byte 
thisRegister = PRESH;
send[0] = (byte)(thisRegister | MPL115A1_READ_MASK);
MySPI.WriteRead(send, result);

byte pressureH = result[0];

//read low byte 
thisRegister = PRESL;
send[0] = (byte)(thisRegister | MPL115A1_READ_MASK);
MySPI.WriteRead(send, result);

//assemble the value
int pressure = (pressureH << 8) | result[0];


I realize this is an old thread, but I did run into it when I was searching for SPI code for this sensor. I came up with something primitive and posted it, here: MPL115A sensor interface for Netduino - Netduino 2 (and Netduino 1) - Netduino Forums

Thanks and Welcome

Thanks cys. I gave up due to a baby in the main and not knowing what I was doing. I shall give it a go. If you have any more info I would be greatful. I shall do some more google searching.

i’m stuck with this issue too… cys’sw link i can not access… any help?


Here it is