Hello all,
Could anyone explain me what's wrong with this code in a C++ library:
.h file
class PSM
{
public:
PSM(uint32_t sensePin, uint32_t mode = RISING);
static void onInterrupt();
unsigned int cps();
private:
void calculateSkip();
volatile unsigned int _a;
};
.cpp file
static PSM * _thePSM;
PSM::PSM(uint32_t sensePin, uint32_t mode)
{
_thePSM = this;
pinMode(sensePin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(sensePin), onInterrupt, mode);
}
void PSM::onInterrupt(void)
{
_thePSM->calculateSkip();
}
void PSM::calculateSkip(void)
{
PSM::_a++;
}
unsigned int PSM::cps()
{
return PSM::_a
}
The point is obviously to count impulses on a sensePin.
This code works on AVR, but doesn't work on STM32.
If I write the same attachInterrupt in the .ino, it works.
What could be wrong with the code? I'm not a C++ pro, maybe it's something obvious.
I've also used this as a reference.