Go Down

Topic: MultiSpeed I2C Scanner - 50,100,200,400 KHz. (Read 9656 times) previous topic - next topic

orangkucing

#15
Jun 17, 2014, 07:46 pm Last Edit: Jun 17, 2014, 07:55 pm by orangkucing Reason: 1
Two modifications were necessary for MultiSpeed I2C Scanner to work with Due.

1. TWBR must be emulated by adding the following code after the #include statements (cf.  https://github.com/jrowberg/i2cdevlib/issues/48):

#if defined(__arm__)
class TWBRemulation
{
public:
   inline TWBRemulation & operator = (int val) __attribute__((always_inline)) {
   if (val == 12 || val == ((F_CPU / 400000) - 16) / 2) {
       #if F_BUS == 48000000
       I2C0_F = 0x1A; // 400 kHz
       #elif F_BUS == 24000000
       I2C0_F = 0x45; // 400 kHz
       #endif
   }
   return *this;
}
};
TWBRemulation TWBR;
#endif


2. Due's pull-up resistors are unsuitable for most I2C devices (cf. http://forum.arduino.cc/index.php?PHPSESSID=n5nfq19euhrhc12gtv03r0j3j2&topic=146802.15). Thus I removed the onboard network resistor, and used external 4.7k pull-ups.

(Maybe using the Wire1 library instead of Wire and connecting an externally-pulluped I2C bus to SCL1/SDA1 pins will work, too, but I just checked the above mentioned workaround works.)

And please use a Nightly build version of Arduino IDE. Because the Wire library before 1.5.7 including the current 1.5.6r2 has a serious bug on the return values of TwoWire::endTransmission function. (cf. https://github.com/arduino/Arduino/pull/1994 )

robtillaart

Thanks for these additions  (have no time to confirm, sorry )

Did you get meaningful results with the I2C scanner now?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

orangkucing

#17
Jun 18, 2014, 12:49 am Last Edit: Jun 18, 2014, 01:06 am by orangkucing Reason: 1
Oh....
I'm sorry.  This morning I found the addition 1 is meaningless and not working as multi speeds.  It only scans at 100kHz.
So if you only need to scan at 100kHz, simply comment out the TWBR code and use the nightly ide 1.5.7.

(cf. http://www.i2cdevlib.com/forums/topic/88-mpu-dmp6-with-arduino-due-twbr-not-declared/)

robtillaart

#18
Jul 05, 2014, 11:02 am Last Edit: Jul 05, 2014, 11:38 am by robtillaart Reason: 1
updated to 0.1.04  (see first post)

main change is restricting the # addresses to be scanned as I2C address 0..7 and 120..127 have special meanings.

or download from here - https://github.com/RobTillaart/Arduino/tree/master/sketches/MultiSpeedI2CScanner -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

updated to version 0.1.05 on github
- https://github.com/RobTillaart/Arduino/tree/master/sketches/MultiSpeedI2CScanner -

not tested enough imho, so not updated in the first post.

as always comments and remarks are welcome.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up