# attachInterrupt() cause to hard fault

**URL:** <https://community.particle.io/t/attachinterrupt-cause-to-hard-fault/51431>\
**Category:** Troubleshooting\
**Tags:** photon\
**Created:** [July 29, 2019, 2:09pm UTC](https://community.particle.io/t/attachinterrupt-cause-to-hard-fault/51431 "2019-07-29T14:09:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://community.particle.io/u/Omri)\
**Post date:** [July 29, 2019, 2:09pm UTC](https://community.particle.io/t/attachinterrupt-cause-to-hard-fault/51431/1 "2019-07-29T14:09:36Z")

</div>

Hi everyone,

I need to declare 3 interrupts in my firmware  
1 - on pin P1S1  
2 - on pin P1S2  
3 - on pin TX (#64)

The first two interrupt are working well, but when I tried to add the 3rd interrupt, it caused to a hard fault.

I am pretty sure that it’s not related to syntax because I used interrupts before and it worked well.

maybe it’s related to this pice information in the particle reference:

![1](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/9/7/971d865386fb071d255d6ecdfbd3a71804f699da.png)

**Fan.h:**

```auto
#include "Particle.h"

#define FAN_PIN RX
#define FAN_TACHO TX
#define INIT_FAN_VALUE 255 //off

class Fan
{
private:
    uint8_t fanSpeed;

    void ISRfunc();

public:
    Fan();
    void setup();
    void run();
    void run(uint8_t);

    void setFanSpeed(uint8_t);
};

```

**Fan.cpp:**

```auto
#include "Fan.h"

Fan::Fan()
{
    this->setFanSpeed(INIT_FAN_VALUE);
}
void Fan::setup()
{
    pinMode(FAN_PIN, OUTPUT);
    this->run();

    pinMode(FAN_TACHO, INPUT);
    attachInterrupt(FAN_TACHO, &Fan::ISRfunc, this, CHANGE);
}
void Fan::run()
{
    analogWrite(FAN_PIN, this->fanSpeed);
}
void Fan::run(uint8_t fanSpeed)
{
    if (fanSpeed > 255 || fanSpeed < 0)
    {
        return;
    }

    analogWrite(FAN_PIN, fanSpeed);
}

void Fan::setFanSpeed(uint8_t fanSpeed)
{
    if (fanSpeed <= 255 || fanSpeed >= 0)
    {
        this->fanSpeed = fanSpeed;
    }
}

void Fan::ISRfunc()
{
    Particle.publish("test", "*#*#*#*");
    delay(200);
}

```

I hope that someone can help me with this issue soon.  
Thanks in advance,  
Omri

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 29, 2019, 2:28pm UTC](https://community.particle.io/t/attachinterrupt-cause-to-hard-fault/51431/2 "2019-07-29T14:28:50Z")

</div>

@Omri, you shouldn’t be doing a `Particle.publish()` within an ISR. Nor should you have a `delay()` as millis() don’t run in an ISR and it could block other interrupts for the duration. Rember that ISR’s need to be lite and fast. For your ISR, you should set a flag or increment a counter that you test and handle in `loop()`.

---

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://community.particle.io/u/Omri)\
**Post date:** [July 29, 2019, 2:39pm UTC](https://community.particle.io/t/attachinterrupt-cause-to-hard-fault/51431/3 "2019-07-29T14:39:32Z")

</div>

@peekay123, Thank you very much!!!

I did delete the Particle.publish and it’s work now.
