A couple of weeks back I was having a great time getting a Sparkfun MPU9250 working on a Due, using Kris Winer’s MPU9250 library. At one point it ran really well - reporting at a Mahony Quaternion filter update rate of ~ 830Hz … very cool. Little did I know my success was about to nose-dive!
The MPU9250 uses I2C so it was connected to SDA/SCL pins 20/21. But I wanted to move it to the other I2C port SDA1/SCL1 on pins 70/71 (Wire1). Things have been going downhill ever since … I never got SDA1/SCL1 working, but worse I cannot even get SDA/SCL working any more.
I’ve tried various hardware. First I tried using my second Due with another MPU9250. No go. Then I reverted to a BMP180 pressure sensor which also uses the I2C port, and a different sketch. None of this worked.
So I checked all the peripherals and sketches on a Uno - everything worked!
Perhaps I’ve damaged both my Due boards (they work fine otherwise) but maybe I’ve got something wrong in the way I have coded for the I2C port. I’ve attached two of the three sketches I tried, one reads a BMP-180 the other is for calibrating the magnetometer on a MPU9250.
All my sketches use this code to initialise the I2C port, for Uno or Due:
#if !defined(DUE) // (not for Due) TWBR = 12; // TWI (I2C) Bit Rate Register: set fast mode 400kb/s Serial << F(" * [UNO] TWBR: ") << TWBR << '\n'; #elif defined(DUE) //#define Wire Wire1 // use Due's second I2C port: SDA1/SCL1 on pins D70/D71 //extern TwoWire Wire1; //Serial << F("* using Wire1") << '\n'; //won't compile. Due equivalent to TWBR on Uno?) Wire.begin(); // not needed UNO ! Serial << F(" * [DUE]\n"); //Serial << F(" * [DUE] TWI_CWGR:") << TWI_CWGR << '\n'; // won't compile! what is Due equivalent to Uno's TWBR ? #endif
I never found out how to ensure the Due I2C was in FAST mode (400kHz) . Maybe this is the issue?
Hopefully I’ve just missed something in the code - any / all suggestions appreciated
DueBMP.zip (2.15 KB)
MPUmagCal.zip (6.31 KB)