Teensy 3.2 Interrupt doesn't work. HELP

Status
Not open for further replies.

vbonis

New member
Hello,

I need help, the interrupti in my program is not working, I tried everything, I read some posts here in the forum, but nothing. I tried to use other pins and it also did not work. Below is the code (Arduino IDE), if you can help me, I thank you!

Code:
volatile int estado = LOW;  //variavel estado para interrupçao
volatile int PinInt = 15;   //Pino de Interrupção

void ligaDesliga();   //Função de interrupção

void setup()
{
     attachInterrupt(PinInt, ligaDesliga, RISING);    //incializa a interrupção
}

void loop()
{
...
}

void ligaDesliga()
{
  static unsigned long antigoMillis = 0;    
  unsigned long novoMillis = millis();      
  if(novoMillis - antigoMillis<50)          
  {  }
  else
  {
    estado = !estado;
    antigoMillis = novoMillis;
  }
}

The code is compiled and uploaded, but not work.

thanks in advance!
 
You need to use pinMode(15, INPUT) or pinMode(INPUT_PULLUP). Without this, the pin defaults to a disabled low-power state.
 
Thank you so much!!!


The same code works on arduino nano, so I thought it would work on Teensy as well.

Now it's working, thank you !!
 
AVR and most older 8 bit chips default their pins to input mode. That's convenient, but if the pins are left unconnected or used with analog signals, they can "float" to voltages near the logic switching threshold, which causes the input transistors to consume more power as they partially turn on. This was less of an issue with older silicon technology, but the problem gets worse with more modern lower voltage parts.

The ARM-based chip on Teensy defaults the pins and nearly all other hardware to a low power disabled state. This requires more work to initialize, but it's a tremendous advantage if you're building a very low power project or anything that runs from a battery. Everything starts out in its lowest power mode and only can consume power when you enable it.

Of course Arduino was designed around the older parts, and it's meant to be simple, so it follows the model of everything is turned on by default. Several times I've considered adding startup code to put all the pins into input mode. But that really can be a disadvantage if you want to have low power usage, so Teensy defaults the pins to disabled.
 
Status
Not open for further replies.
Back
Top