Thanks Dave…i have read those sections and applied the logic but its not working as expected…
MUX_BTN_OPTO_FETS = new PortExpander.Mcp23017(0x23, null);
MUX_BTN_OPTO_FETS.PinDirectionB(PortExpander.Pin.ALL, PortExpander.Direction.Input);
MUX_BTN_OPTO_FETS.SetConfigRegister(PortExpander.ConfigRegister.MIRROR);
MUX_BTN_OPTO_FETS.PinInterruptControlB(PortExpander.Pin.ALL, PortExpander.InterruptControl.PreviousValue);
MUX_BTN_OPTO_FETS.PinDefaultValueB(PortExpander.Pin.ALL, false);
MUX_BTN_OPTO_FETS.PinInterruptOnChangeB(PortExpander.Pin.ALL, true);
MUX_BTN_OPTO_FETS.PinDirectionA(PortExpander.Pin.ALL, PortExpander.Direction.Input);
MUX_BTN_OPTO_FETS.PinDefaultValueA(PortExpander.Pin.ALL, false);
MUX_BTN_OPTO_FETS.PinInterruptControlA(PortExpander.Pin.ALL, PortExpander.InterruptControl.PreviousValue); //Doesn't interupt if is use PortExpander.InterruptControl.DefaultValue
MUX_BTN_OPTO_FETS.PinInterruptOnChangeA(PortExpander.Pin.ALL, true);
static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
{
if (LogLevel >= LoggingLevel.debug) Debug.Print("Button Pressed InterruptCount[" + InterruptCount++ + "]");
InputsB = MUX_BTN_OPTO_FETS.ReadPinsB(PortExpander.Pin.ALL);
InputsA = MUX_BTN_OPTO_FETS.ReadPinsA(PortExpander.Pin.ALL);
}
public void Reset()
{
if (resetPin != null)
{
resetPin.Write(false);
Thread.Sleep(5);
resetPin.Write(true);
Thread.Sleep(5);
}
else
{
//set default Reset values if not using hardware reset pin
//Write(_IODIRA, 0x00);//00=OUTPUT
Write(_IPOLA, 0x00);
Write(_GPINTENA, 0x00);//Interupts off
Write(_DEFVALA, 0x00);
Write(_INTCONA, 0x00);
Write(_IOCONA, 0x00);
Write(_GPPUA, 0x00);
Write(_INTFA, 0x00);
Write(_INTCAPA, 0x00);
Write(_GPIOA, 0x00);
Write(_OLATA, 0x00);
//Write(_IODIRB, 0x00);//00=OUTPUT
Write(_IPOLB, 0x00);
Write(_GPINTENB, 0x00);//Interupts off
Write(_DEFVALB, 0x00);
Write(_INTCONB, 0x00);
Write(_IOCONB, 0x00);
Write(_GPPUB, 0x00);
Write(_INTFB, 0x00);
Write(_INTCAPB, 0x00);
Write(_GPIOB, 0x00);
Write(_OLATB, 0x00);
}
}
My board will somtimes feeze if the interrupt get called too often?
Are their any best practices when using interrupts? SHoud i avoid other threads etc?