Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

MCP23017 Interrupts


  • Please log in to reply
5 replies to this topic

#1 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 25 March 2013 - 02:37 PM

I can do basic IO on this chip without any issues but can i get the interrupt to work, no. Been at it for a few days and im not making any progress, please help!!!!

 

Hardware setup:

NP2+, clk & data lines have pull up resistors, 2 leds on the output of the mcp chip. 2 simple switch for the input with pull up resistors which is shorted to ground when switched. INTA on the mcp has a direct connection to the NP2+ to DIO0.

 

private void SetupPort(Port port){byte IODIA = IODIRA;byte IOCONAddress = IOCON;byte GPINTENAddress = GPINTENA;byte INTCONAddress = INTCONA;byte INTCAPAddress = INTCAPA;byte DEFVALAddress = DEFVALA;if (port == Port.PortB){IODIA = IODIRB;GPINTENAddress = GPINTENB;INTCONAddress = INTCONB;INTCAPAddress = INTCAPB;DEFVALAddress = DEFVALB;}// I/O expander configuration 1010 0000this.device.Write(new byte[] { IOCONAddress, 0xA0 });// Interrupt on change pin 00001111 first 4 are enabled only cus they are inputsthis.device.Write(new byte[] { GPINTENAddress, 0x0F });// default value to compare before the interrupt hitsthis.device.Write(new byte[] { DEFVALAddress, 0x0F });// Interrupt on change control reg, interrupts on default valuethis.device.Write(new byte[] { INTCONAddress, 0x0F });// clear the interupt capture regbyte[] ReadBuffer = new byte[] { INTCAPAddress };this.device.Read(ReadBuffer);// Direction register 11110000 first 4 are outputs and the rest are inputsthis.device.Write(new byte[] { IODIA, 0xF0 });// set outputs to 0//SetIOPort(port, 0);}

 

basicaly the setup is the first 4 bits to be inputs (interrupt driven) and the next 4 bits as outputs.

 

ive configured to only go high when it receives a high level from the input.

 

Its not working at all.



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 25 March 2013 - 09:33 PM

enum Register        {            IODDIR_A = 0x00, // Input/Output address            IPOL_A = 0x02, // sets the polarity of the input pin (invert)            GPINTEN_A = 0x04, // enable interrupt register            DEFVAL_A = 0x06, // default values for interrupt register            INTCON_A = 0x08, // interrupt register            IOCON_A = 0x0A, //             GPPU_A = 0x0C, // pullup resistor addressout            INTF_A = 0x0E,            INTCAP_A = 0x10,            GPIO_A = 0x12, // pins            OLAT_A = 0x14,            IODDIR_B = 0x01,            IPOL_B = 0x03,            GPINTEN_B = 0x05,            DEFVAL_B = 0x07,            INTCON_B = 0x09,            IOCON_B = 0x0B,            GPPU_B = 0x0D,            INTF_B = 0x0F,            INTCAP_B = 0x11,            GPIO_B = 0x13,            OLAT_B = 0x15,        }base.Write(new Byte[] { (Byte)Register.IODDIR_B, 0xFF });base.Write(new Byte[] { (Byte)Register.GPINTEN_B, 0xff });base.Write(new Byte[] { (Byte)Register.GPPU_B, 0xFF });base.Write(new Byte[] { (Byte)Register.DEFVAL_B, 0xFF });base.Write(new Byte[] { (Byte)Register.INTCON_B, 0x00 });base.WriteRead(new Byte[] { (Byte)Register.INTCAP_B }, new Byte[1]);

?

?

?

?

?

?

?

?

 

 

thats working for me.

 

interruptB = new InterruptPort(                    InterruptPortB, true,                     Port.ResistorMode.PullUp,                     Port.InterruptMode.InterruptEdgeLow);void interruptB_OnInterrupt(uint data1, uint data2, DateTime time)        {            Byte[] tmp = new Byte[1];            base.WriteRead(new Byte[] { (Byte)Register.INTF_B }, tmp);            base.WriteRead(new Byte[] { (Byte)Register.INTCAP_B }, new Byte[1]);            if (tmp[0] == 1)            {                Debug.Print("durchgangsschalter");            }        }

 

 

edit: the value wich pin has changed doies not come as decimal, like 1,2,3 and so on. its binary 001 is pin (3 (or 2 when you start counting with 0))



#3 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 27 March 2013 - 09:27 AM

hi, tried your code and it does not work for me :(



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 27 March 2013 - 10:20 PM

netmf-toolbox also has a driver.

 

but my code is 100% working, your doing something wrong, maybe the interrupt connection or something like that.

 

 

did you use my register-addresses too ?

also, my code uses portb, and fires when something goes _low_ on a port



#5 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 28 March 2013 - 03:22 PM

netmf-toolbox does not do interrupts.

 

Changed everything to adapt to your code and still nothing.

 

Thanks for help but ive implemented a software interrupt routine now. :)



#6 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 29 March 2013 - 12:00 AM

thats the worst thing todo, so you loose the benefit from not having to poll it all the time cos of the interrupt.

 

post your whole code here. ill have a look






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.