0

MPL3115A2 not working
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: MPL3115A2 not working

by FODRIGO on Mon Jul 13, 2015 11:30 pm

So, any solution for MPL3115A2 to work on DUE?
Also, I couldn't put work together the DOF 10 and AM2315 on DUE? However, they working fine alone.
Please, any help will be very helpful.
Thanks.

FODRIGO
 
Posts: 3
Joined: Mon Jul 13, 2015 11:24 pm

Re: MPL3115A2 not working

by adafruit_support_rick on Tue Jul 14, 2015 10:03 am

FODRIGO wrote:So, any solution for MPL3115A2 to work on DUE?

I gave up on that. It seems to be a problem with the I2C library on the Due.

Are you running the AM2315 from 5V? You'll need to use a level-shifter to bring it down to 3.3V
https://www.adafruit.com/products/757

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: MPL3115A2 not working

by Nemonic on Tue Oct 27, 2015 10:19 am

Hi,

Someone submitted a fix to the bug that is causing many i2c sensors, including this one, to not work with the Due. You will need to manually patch/update your SAM Wire.cpp and Wire.h files and alter the example code for the sensors.

The problem is caused by the SAM Wire.cpp not respecting/implementing the sendStop parameters in several/all TwoWire class methods.
See: C:\Users\<USERNAME>\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.4\libraries\Wire\Wire.cpp and Wire.h

Here is the link to the github issue where user AmLimit supplies a fix. You will need to edit the above mentioned files and add the code in the link.
https://github.com/arduino/Arduino/issues/2428

or grab the already updated files here

https://github.com/arduino/Arduino/tree ... aries/Wire


To then use the sensor you need to modify the Adafruit MPL3115A2 library/example methods like the following (there are other methods that also need modification!).

Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_MPL3115A2::read8(uint8_t a) {
  // Fix for the Due!
  Wire.requestFrom((uint8_t) MPL3115A2_ADDRESS, (uint8_t) 1, (uint32_t) a, (uint8_t) 1);

  // The following doesn't work on the Due as endTransmission((sendStop) false) isn't respected.
  /*
  Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device
  Wire.write(a); // sends register address to read from
  Wire.endTransmission(false); // end transmission 
  Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)1);// send data n-bytes read
  */
  return Wire.read(); // receive DATA
}

This fix wasn't in the most recent nightly build of the Arduino SDK for me, in spite of being accepted and merged into the master branch.

Hope this helps fix some problems people have been having with i2c on the Due. I suspect this is the root cause behind a lot of Due i2c problems, and problems other customers are having with Adafruit i2c sensors on the Due.

Nemonic
 
Posts: 4
Joined: Tue Oct 27, 2015 10:05 am

Re: MPL3115A2 not working

by adafruit_support_rick on Wed Oct 28, 2015 4:20 am

Wow! Thanks for posting - I knew it had to be a bug in the Due Wire library. This should help a lot of people.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: MPL3115A2 not working

by adafruit2 on Wed Oct 28, 2015 9:37 am

thx - but it seems that was patched 4 months ago? if you get the latest board manager package you should be good to go, then right?

adafruit2
Site Admin
 
Posts: 20216
Joined: Fri Mar 11, 2005 7:36 pm

Re: MPL3115A2 not working

by Nemonic on Wed Oct 28, 2015 10:09 am

adafruit2 wrote:thx - but it seems that was patched 4 months ago? if you get the latest board manager package you should be good to go, then right?


I don't think so, I have "Arduino SAM Boards v1.6.4" in board manager and this "fix" wasn't included.

In any case, you have to use the new overloaded method requestFrom with the iaddress and isize which is completely different from how you would interface with the device on Uno/Mega/Nano etc.

I guess you would need to change your example/library code for i2c sensors which use repeat start on the DUE, but when the fix isn't even included in the platform SDK idk what you can do. This doesn't look like something you can work around in example/library code, the Wire.cpp needs modification. Perhaps add some compiler warning/error for DUE users?

At least we know what the problem is now. :)

Nemonic
 
Posts: 4
Joined: Tue Oct 27, 2015 10:05 am

Re: MPL3115A2 not working

by protonstorm on Wed Oct 28, 2015 10:50 am

I don't think so, I have "Arduino SAM Boards v1.6.4" in board manager and this "fix" wasn't included.


Yeah I just checked my wire.cpp and it's not there. I guess this fix didn't make it into the release that you can download with the board manager (1.6.4)

protonstorm
 
Posts: 12
Joined: Wed Jun 17, 2015 5:37 am

Re: MPL3115A2 not working

by setishock on Fri Nov 27, 2015 2:27 pm

I was all set to get a DUE but if I'm reading this right, it won't communicate with the sensor boards like an IMU? This is bad as my whole design for a flight controller revolves around a DUE.

setishock
 
Posts: 15
Joined: Wed Nov 18, 2015 7:44 am

Re: MPL3115A2 not working

by adafruit_support_rick on Sat Nov 28, 2015 8:55 am


adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: MPL3115A2 not working

by Nemonic on Sun Nov 29, 2015 9:38 pm

setishock wrote:I was all set to get a DUE but if I'm reading this right, it won't communicate with the sensor boards like an IMU? This is bad as my whole design for a flight controller revolves around a DUE.


The SAM library should now been updated with the additional methods if you updated to the latest board in the IDE. It's worth looking at the patch and reading the info to understand a bit better how it works and how you need to modify your own code to make the sensors work. You can also check your board files manually to make sure the patch is included.

I've successfully communicated with several I2C chips which require repeat starts to function on the due, so if you put the time in it, it should work.

Nemonic
 
Posts: 4
Joined: Tue Oct 27, 2015 10:05 am

Re: MPL3115A2 not working

by nfiorilla on Mon Feb 22, 2016 6:00 pm

Hi Nemonic,

Could you please tell me which other methods from the MPL3115A2 library/example do you modify and the modifications you made? I need help making a Adafruit 10-DOF sensor to work with the Arduino DUE.

Nemonic wrote:Hi,
To then use the sensor you need to modify the Adafruit MPL3115A2 library/example methods like the following (there are other methods that also need modification!).

Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_MPL3115A2::read8(uint8_t a) {
  // Fix for the Due!
  Wire.requestFrom((uint8_t) MPL3115A2_ADDRESS, (uint8_t) 1, (uint32_t) a, (uint8_t) 1);

  // The following doesn't work on the Due as endTransmission((sendStop) false) isn't respected.
  /*
  Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device
  Wire.write(a); // sends register address to read from
  Wire.endTransmission(false); // end transmission 
  Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)1);// send data n-bytes read
  */
  return Wire.read(); // receive DATA
}



Thank you!!!!

nfiorilla
 
Posts: 12
Joined: Thu Feb 18, 2016 9:52 pm

Re: MPL3115A2 not working

by Nemonic on Mon Feb 22, 2016 7:09 pm

Hi,

I don't have the code, but iirc any functions/methods that issue "Wire.endTransmission(false)".

The quoted code in your post which is commented out is the typical pattern seen when a request with sendStop false is used. You need to use the new (as of SAM 1.6.6) overloaded Wire.requestFrom method and pass in the register address as a parameter rather than using Wire.write to send the register address separately.

This line
Code: Select all | TOGGLE FULL SIZE
Wire.requestFrom((uint8_t) MPL3115A2_ADDRESS, (uint8_t) 1, (uint32_t) a, (uint8_t) 1);


Replaces these 4 lines for the DUE.
Code: Select all | TOGGLE FULL SIZE
  Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device
  Wire.write(a); // sends register address to read from
  Wire.endTransmission(false); // end transmission 
  Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)1);// send data n-bytes read


Wire.endTransmission(false) doesn't work correctly on the DUE, so you must instead use the overloaded Wire.requestFrom which sets the address AND data/register values.

Internally i guess it's just a quirk of how the SAM implements I2C functionality vs ATmega.

Nemonic
 
Posts: 4
Joined: Tue Oct 27, 2015 10:05 am

Re: MPL3115A2 not working

by nfiorilla on Tue Feb 23, 2016 11:04 pm

Hi Nemonic,

thanks for your help.

I have made the modifications you said me but I can´t make my Adafruit 10-DOF works with the Arduino Due.

I also add some println to the "requestFrom" function from Wire.cpp and I can see that this IF:

Code: Select all | TOGGLE FULL SIZE
if (TWI_WaitByteReceived(twi, RECV_TIMEOUT))
          {
             rxBuffer[readed++] = TWI_ReadByte(twi);
          }
          else
          {
             break;
          }


Always fails and go through the break!
Do you have any idea why this is happening??
Is there another way to test the sensor, to see if it has any hardware damage? maybe coneccting it to a digital input an plot the input

Thanks for your help.

nfiorilla
 
Posts: 12
Joined: Thu Feb 18, 2016 9:52 pm

Re: MPL3115A2 not working

by witc68 on Sat May 07, 2016 6:01 am

Hi,
I have a MPL3115A2, but I do not know if these values which I get are OK. Is normal that MPL is too noisy?
https://www.youtube.com/watch?v=d3YJpVP ... e=youtu.be

witc68
 
Posts: 1
Joined: Sat May 07, 2016 5:59 am

Re: MPL3115A2 not working

by adafruit2 on Sat May 07, 2016 7:02 pm

thats normal, its not a precision device

adafruit2
Site Admin
 
Posts: 20216
Joined: Fri Mar 11, 2005 7:36 pm

Please be positive and constructive with your questions and comments.