Relative order of pin changes on port

Status
Not open for further replies.

ecurtz

Well-known member
I have a case where I'd like to essentially latch a value from one pin on the edge of another pin on the same port, and reading the pin in my interrupt isn't fast enough to reliably capture the state.

I've tried this:
Code:
const static uint8_t  DMD_ROW_DATA = 16;
const static uint8_t  DMD_ROW_CLK = 17;

setup()
{
  attachInterrupt(digitalPinToInterrupt(DMD_ROW_CLK), row_clk_isr_wpc, FALLING);
}

void row_clk_isr_wpc(void) 
{
  if (digitalReadFast(DMD_ROW_DATA)) {
    //
  }
}

And this:
Code:
const static uint8_t  DMD_ROW_DATA = 16;
const static uint8_t  DMD_ROW_CLK = 17;
volatile bool rowZero = false;

setup()
{
  attachInterrupt(digitalPinToInterrupt(DMD_ROW_DATA), row_zero_isr, CHANGE);
  attachInterrupt(digitalPinToInterrupt(DMD_ROW_CLK), row_clk_isr_wpc, FALLING);
}

void row_zero_isr(void)
{
  rowZero = digitalReadFast(DMD_ROW_DATA);
}

void row_clk_isr_wpc(void) 
{
  if (rowZero) {
    //
  }
}

Both of which work at 120MHz, but not 96MHz because of the brief interval that DMD_ROW_DATA stays valid after the DMD_ROW_CLK change. I assume the second would work if I changed pin order because of how the portb_interrupt calls your handlers, or if I used some sort of timer (or flag?) to check if it changed during the same portb_interrupt, or I could replace the portb_interrupt completely, but none of those seem like very elegant solutions. Is there a cleaner way of doing this I'm missing?
 
Status
Not open for further replies.
Back
Top