Pages: 1 [2]   Go Down
Author Topic: MultiSpeed I2C Scanner - 50,100,200,400 KHz.  (Read 6147 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 )
« Last Edit: June 17, 2014, 12:55:33 pm by orangkucing » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Did you get meaningful results with the I2C scanner now?
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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/)
« Last Edit: June 17, 2014, 06:06:34 pm by orangkucing » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 -
« Last Edit: July 05, 2014, 04:38:34 am by robtillaart » Logged

Rob Tillaart

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rob Tillaart

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

Pages: 1 [2]   Go Up
Jump to: