centipede (mcp23017) - arduinio e interrupt

Ciao a tutti,
sto litigando con lo shield centipede (ho bisogno di altre linee di i/o) che altro non è che 4 mcp23017.
Le operazioni banali non sono un problema… quindi riesco a leggere e scrivere (testato)… ma vorrei sfruttare la possibilità del 23017 di generare un irq qualora ci sia un cambiamento sui piedini…
ovvero… ho collegato l’INTA del mcp23017 al pin 18 del mio MEGA…
la gestione degli irq su arduino non è un problema… ma per lo stub vado in polling sul piedino 18…
ebbene… non mi arriva mai nessuna segnalazione!!!
grazie e birra offerta! :wink:

#include <Wire.h>

// MCP23017 registers (everything except direction defaults to 0)

#define IODIRA   0x00   // IO direction  (0 = output, 1 = input (Default))
#define IODIRB   0x01
#define IOPOLA   0x02   // IO polarity   (0 = normal, 1 = inverse)
#define IOPOLB   0x03
#define GPINTENA 0x04   // Interrupt on change (0 = disable, 1 = enable)
#define GPINTENB 0x05
#define DEFVALA  0x06   // Default comparison for interrupt on change (interrupts on opposite)
#define DEFVALB  0x07
#define INTCONA  0x08   // Interrupt control (0 = interrupt on change from previous, 1 = interrupt on change from DEFVAL)
#define INTCONB  0x09
#define IOCON    0x0A   // IO Configuration: bank/mirror/seqop/disslw/haen/odr/intpol/notimp
//#define IOCON 0x0B  // same as 0x0A
#define GPPUA    0x0C   // Pull-up resistor (0 = disabled, 1 = enabled)
#define GPPUB    0x0D
#define INFTFA   0x0E   // Interrupt flag (read only) : (0 = no interrupt, 1 = pin caused interrupt)
#define INFTFB   0x0F
#define INTCAPA  0x10   // Interrupt capture (read only) : value of GPIO at time of last interrupt
#define INTCAPB  0x11
#define GPIOA    0x12   // Port value. Write to change, read to obtain value
#define GPIOB    0x13
#define OLLATA   0x14   // Output latch. Write to latch output.
#define OLLATB   0x15


int port=0x23;  // MCP23017 is on I2C port 0x20



volatile boolean keyPressed;

// set register "reg" on expander to "data"
// for example, IO direction
void expanderWriteBoth (const byte reg, const byte data ) 
{
  Wire.beginTransmission (port);
  Wire.send (reg);
  Wire.send (data);  // port A
  Wire.send (data);  // port B
  Wire.endTransmission ();
} // end of expanderWrite

// read a byte from the expander
unsigned int expanderRead (const byte reg) 
{
  Wire.beginTransmission (port);
  Wire.send (reg);
  Wire.endTransmission ();
  Wire.requestFrom (port, 1);
  return Wire.receive();
} // end of expanderRead

// interrupt service routine, called when pin D2 goes from 1 to 0
void keypress ()
{
   
  keyPressed = true;   // set flag so main loop knows
}  // end of keypress



void setup ()
{



  Wire.begin ();  
 
  Serial.begin (9600);  
   {
    Serial.println(port);
  // expander configuration register
  expanderWriteBoth(GPIOA,0x20);
  expanderWriteBoth (IOCON, 0b01100000); // mirror interrupts, disable sequential mode
 
  // enable pull-up on switches
  expanderWriteBoth (GPPUA, 0xFF);   // pull-up resistor for switch - both ports

  // invert polarity
  expanderWriteBoth (IOPOLA, 0xFF);  // invert polarity of signal - both ports
  
  expanderWriteBoth(INTCONA,0);
 
  // enable all interrupts
  expanderWriteBoth (GPINTENA, 0xFF); // enable interrupts - both ports
  
  // no interrupt yet
  keyPressed = false;

  // read from interrupt capture ports to clear them
  expanderRead (INTCAPA);
  expanderRead (INTCAPB);
  }
 
  pinMode (18, INPUT);      // make sure input
   
 
  
  
  //attachInterrupt(4, keypress, FALLING);
  
}  // end of setup


volatile unsigned long i;

void loop ()
{

int l;
  l=digitalRead(18);
 Serial.print("L=");
 Serial.println(l);
 
 
}  // end of loop