Arduino Mega, SDA/SCL pins, and interrupts

Hi,

I'm working with a Mega 2650. I'm trying to use the external interrupts on pins 20 and 21 (SDA and SCL), and I'm noticing that there's some unpredictable behavior that doesn't seem to be officially documented anywhere.

Specifically, I can't seem to configure those pins to input LOW. I do a digitalWrite(SDApin,LOW) after setting the pinMode to INPUT, but they still read HIGH even if they're not attached to anything.

What I do seem to have found (see this thread) is that SDA and SCL have internal pullup resistors that you have to compensate for with external pulldown resistors (or more pullup ones? I'm seeing conflicting statements from people running into this issue).

The point is, this behavior seems to be very different from how the interrupt pins on (for example) pins 18 and 19 work, where I can set them as LOW or HIGH inputs however I like and they behave accordingly. Can I a) get confirmation that these pins can't be pulled LOW with a digitalWrite like most others, and b) suggest that this be added to the Mega's documentation page in the playground?

I just want to save others the same headache, if they're doing something similar to me. If you need a pair of interrupt pins, either use 18 and 19 OR 20 and 21; don't mix and match them unless you're prepared to handle them differently in code and wiring! (Do I have this right?)

[quote author=Data Graham link=topic=105664.msg792781#msg792781 date=1336913552] Hi,

Specifically, I can't seem to configure those pins to input LOW. I do a digitalWrite(SDApin,LOW) after setting the pinMode to INPUT, but they still read HIGH even if they're not attached to anything.

[/quote]

In that situation the pins are floating - you can't expect to get any definite behaviour from a floating pin.

But isn't that the whole purpose of this technique shown at http://arduino.cc/en/Tutorial/DigitalPins ?

Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input, with 10K being a common value.

There are also convenient 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed in the following manner.

pinMode(pin, INPUT); // set pin to input digitalWrite(pin, HIGH); // turn on pullup resistors

There are not separate pullups for those pins. The Wire library enables the internal pullups, but I don't think it will be invoked unless you call Wire.begin().

When you write LOW to a pin configured as an input, you are just turning off the internal pullups. The pin is floating, not pulled down to ground.

Normally you enable the pull-up resistors to hold the line HIGH when not connected or otherwise driven, and your interrupt drives the line LOW when asserted.