Did attatchInterrupt() change in 1.0?

Hi All…

For the past few hours I have been trying to get an Arduino 022 sketch to work. All of it works except, apparently, the attatchInterrupt() call. The I2c stuff woks fine. The code should catch a hardware interrupt and execute the ISR. It does not on Arduino 22. However, it works perfectly on 1.0.

Here is the code…

Thanks very much.

#include <I2C.h>

#define NXP_UART  0x4D 
#define REG_SPR0 0x38 /* Stoarage register UART 0 */
#define REG_SPR1 0x3A /* Stoarage register UART 1 */

#define REG_IIR 0x10

#define REG_IOCTL 0x70
#define REG_IODIR 0x50
#define REG_INTENA 0x60
#define REG_IOSTATE 0x58

#define INT_PIN 2

const unsigned char LED_DATA = 20;   // Physical pin 23
const unsigned char LED_ERROR = 21; // Physical pin 24
const unsigned char LED_INFO = 22;  // Physical pin 25
const unsigned char L_LED = 7;      // Physical pin 3

volatile int state = LOW;
volatile unsigned char iir;

void setup()
{
  Serial.begin(9600);
  Serial.println("Writing to SPR...");

  // Set up LED for output
  pinMode(LED_ERROR, OUTPUT);  

  I2c.begin();
  I2c.setSpeed(1);
  
  uint8_t buf[2];
  buf[1] = NULL;
  
  I2c.write(NXP_UART, REG_SPR1, 0xAA); 
  I2c.read(NXP_UART, REG_SPR1, 1, buf);

  Serial.print("Read from SPR: ");
  Serial.println(buf[0], HEX);

  Serial.println("Set IO Control - All GPIO pins as IO with latch on");
  I2c.begin();
  I2c.write(NXP_UART, REG_IOCTL, 0x01); 

  Serial.println("Set IO Direction - All GPIO pins as input");
  I2c.write(NXP_UART, REG_IODIR, 0x00); 
  
  Serial.println("Set IO Int Enable - All GPIO pins generate int");
  I2c.write(NXP_UART, REG_INTENA, 0xFF); 
  
  // Attatch interrupt handler
  attachInterrupt(INT_PIN, stateChange, CHANGE);
  
}

void loop()
{
  Serial.print("IIR: ");
  Serial.println(iir, HEX);
  
  delay(250);
}


void stateChange()
{
  state = !state;
  digitalWrite(LED_ERROR, state);
  
  uint8_t buf[2];


  // Read IIR to see what caused the interrupt
  I2c.read(NXP_UART, REG_IIR, 1, buf);
  
  // Clear interrupt condition
  I2c.read(NXP_UART, REG_IOSTATE, 1, buf);
  iir = buf[0];  
}

However, it works perfectly on 1.0.

Is that a problem? What is it you need help with?

PaulS:

However, it works perfectly on 1.0.

Is that a problem? What is it you need help with?

I have not ported my code to 1.0 yet, its still on 22. So I guess the time has come. The only library I am using that I don't have a 1.0 version of yet is SdFat, and I think he did port it. Couldn't find it though. I posted that over in storage.

I have not ported my code to 1.0 yet

but

it works perfectly on 1.0.

OK.

I have a feeling that the first parameter to attachInterrupt() should be 0 or 1 you seem to be using 2

pin 2 is interrupt 0 pin 3 is interrupt 1

I theenk

PS 2 is pin 21 on a Mega 3 is pin 20 on a Mega 4 is pin 19 on a Mega 5 is pin 18 on a Mega

Paul, cut me a little slack here. The test code ran perfectly. Its not even a page. The entire app is about 40 files and none of them are very short. Porting to a new environment is easier said than done.

mmcp42: I have a feeling that the first parameter to attachInterrupt() should be 0 or 1 you seem to be using 2

pin 2 is interrupt 0 pin 3 is interrupt 1

I theenk

PS 2 is pin 21 on a Mega 3 is pin 20 on a Mega 4 is pin 19 on a Mega 5 is pin 18 on a Mega

Ah yes, thank you very much! I can hack the core to fix that little issue.

Probably I'll just port my code instead.