Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARM support #48

Open
pfeerick opened this issue Sep 20, 2013 · 3 comments

Comments

@pfeerick
Copy link

commented Sep 20, 2013

Hi,

When using your MPU6050 DMP6 example with a Digistump DigiX (essentially an enhanced Arduino Due) , I came across three problems.

  1. Firstly, the TWBR does not exist on the ARM platform, so to continue to use that register to set the bus speed, perhaps you should use something like the code below (unless the Arduino guys incorporate a legacy patch themselves). I included it in the I2Cdev.h file and it compiles and works ok on Arduino 1.5.4 on my setup.

  2. Arduino Dues have two I2C buses, and the second one is accessible via the dedicated SDA/SCL pins, and is accessed via Wire1, not Wire. Can you add some sort of flag so the I2Cdev knows to use Wire1 instead of Wire?

  3. the attachInterrupts command doesn't work the same way, you specify the pin not the interrupt, so something like the below snippet fixes that.

Sorry to be wordy, hope this of use to you. :)

Interrupts fix:

// Attach to interrupt 0 (pin 2) on AVR, or pin 2 on ARM
#ifdef __arm__
    attachInterrupt(2, dmpDataReady, RISING);
#else
    attachInterrupt(0, dmpDataReady, RISING);
#endif

TWBR fix:

// Paul Stoffregen AVR TWBR emulation for ARM
// http://forum.pjrc.com/threads/23798-Sabernetics-I2C-OLED-display-Adafruit-SSD1306-library-problem?p=32988&viewfull=1#post32988
#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;
}
};
extern TWBRemulation TWBR;
#endif
@jrowberg

This comment has been minimized.

Copy link
Owner

commented Sep 24, 2013

Hi @pfeerick,

Thanks for putting all of this together. I will definitely add it to the code when I can.

@screamatthewind

This comment has been minimized.

Copy link

commented Nov 28, 2013

Patch works like a charm on the Due, Thanks!

@arivo89

This comment has been minimized.

Copy link

commented Feb 18, 2017

MAy i ask, where do you put these codes in the sketch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.