Go Down

Topic: I2C (SDA/SCL) on Due giving me a hard time ... (Read 96 times) previous topic - next topic


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:

Code: [Select]
 #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 ?

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


The second I2C port on the Due requires pull-up resistors to be added to the SCL and SDA signals.  Also, IIRC, those two pins are paralleled to two other pins, so those pins must be configured as inputs, so they don't interfere with the I2C functionality.  Both I2C ports DO work perfectly.  I use them all the time, and never had a problem.

Ray L.


Sep 24, 2016, 12:05 am Last Edit: Sep 24, 2016, 12:07 am by ninja2
Ray (or anyone else), can you share an example sketch of yours that works with I2C? TIA

I can't get either port working at present so I'm focusing on SDA/SCL pins 20/21 for now. Once I get that working (again!) I will want to get Wire1 on 70/71 working ASAP.

I am aware of need for pull-up resistors on Wire1 port, but not the paralleled pins you mention to be set as inputs. Anyone know which pins these are ?

By the way the MPU9250 does have 10K pull-ups in-built, although the BMP-180 has none. As I understand the Due does have in-built pull-ups on pins 20/21 so both these peripherals should work without adding resistors on that port.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131