Author Topic: [BitCloud] Interrupt handler seems not working  (Read 1713 times)

0 Members and 1 Guest are viewing this topic.

Offline danergoTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
[BitCloud] Interrupt handler seems not working
« on: January 16, 2017, 09:34:47 pm »
Hi,

I've a custom board with ATMEGA256RFR2 on which I'm using 3 simple buttons with pullup resistors. All are connected to the straightforward interrupt pins on INT4,5,6.

I'm trying to use them, but my ISR's are not getting called through BitCloud. (Normally, with manual ISR functions they work fine):

Code: [Select]
volatile uint8_t test = 0;

void Button1InterruptHandler() {
  if (0 == test) {
    test=1;
    PORTB ^= (1<<PB3); //This should flip PB3 only once. But it remains VDD.
  }
}

uint8_t setupISR() {
  DDRB |= (1<<PB3);
  PORTB |= (1<<PB3); //Test pin, set it to VDD

  if (0 != HAL_RegisterIrq(INT4, IRQ_LOW_LEVEL, Button1InterruptHandler))
    return BC_FAIL;
}

...
setupISR();
...

Do I miss something? I wouldn't like to deepdive into HAL functions if the code above contains some simple bug.

Thanks!
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11259
  • Country: us
    • Personal site
Re: [BitCloud] Interrupt handler seems not working
« Reply #1 on: January 16, 2017, 09:46:46 pm »
If IRQ pin remains low, it will trigger a repeated interrupt. You need to disable interrupts in the handler and then poll until level goes back up. Look at how BSP code for buttons works.

Did not notice your test flag protection.

The code for interrupts is essentially equivalent to manual setup, so they typically works as expected, so I really don't know what is going on.

EDIT: did you actually configure the INT4 pin to be an input?

And you also need to enable IRQ after you register the handler:
Code: [Select]
HAL_EnableIrq(IRQ_4);

And it should be called IRQ_4, not INT4.
« Last Edit: January 17, 2017, 12:35:33 am by ataradov »
Alex
 
The following users thanked this post: danergo

Offline danergoTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] Interrupt handler seems not working
« Reply #2 on: January 17, 2017, 06:45:33 am »
And you also need to enable IRQ after you register the handler:
Code: [Select]
HAL_EnableIrq(IRQ_4);
That's the one I missed! Thanks!  :-+

EDIT: did you actually configure the INT4 pin to be an input?
Yes, INT4 is configured, but the sample code was not complete - sorry.

And it should be called IRQ_4, not INT4.
Both INT4 and IRQ_4 equals 4 actually.  :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf