Skip to main content
9 votes
Accepted

What is the right way to query an I2C device from an interrupt service routine?

Just because a pin is called "interrupt" doesn't mean that you have to read it using an interrupt input. The INTx pins of the ADXL345 are simple "level" outputs. All the time there is an "interrupt" ...
Majenko's user avatar
  • 105k
8 votes
Accepted

How to get around passing a variable into an ISR

I would follow Delta_G's advice, and write an ISR that counts the steps and does nothing more. As a general rule, you want to do as little as possible within an ISR. I would even avoid floating point ...
Edgar Bonet's user avatar
  • 43.3k
6 votes
Accepted

Why no brackets after Interrupt routine inside attachInterrupt

It is right, that you are putting brackets after the function name if you are calling it. But with attachInterrupt() you just want to give it the information, which function to call in case of an ...
chrisl's user avatar
  • 16.3k
6 votes
Accepted

Using interrupts as flags/latches without any ISR

The answer to your question is: yes, you can use an interrupt flag even if the interrupt itself is disabled. The flag is raised whenever the peripheral detects the relevant event. You can check it at ...
Edgar Bonet's user avatar
  • 43.3k
5 votes

What is the right way to query an I2C device from an interrupt service routine?

Majenko's answer is useful — you can simply forego the use of interrupts for this and poll the pin directly in your main loop. Especially on AVR where the external pins are exposed as registers which ...
hobbs's user avatar
  • 234
5 votes
Accepted

ISR for very fast processes, strange code found. Has ISR effect on timer behaviour?

Why isn't CTC mode used by setting WGM21 in TCCR2A? As we cannot read the author's mind, we cannot say for sure. That being said, to me, the most likely reason is that either the author was not aware ...
Edgar Bonet's user avatar
  • 43.3k
4 votes
Accepted

How to set up one second interrupt/ISR for ds3231 RTC

This answer addresses the original question of why the interrupts didn't work. I happened to have a DS3231 lying around so I made up a test. Interrupt vs pin number First, this is wrong in your code:...
Nick Gammon's user avatar
  • 38.4k
4 votes

Is possible to set a pin faster than digitalWrite?

Since pin 11 on the ATmega328P is PB3: PINB |= _BV(PB3);
Ignacio Vazquez-Abrams's user avatar
4 votes

Is possible to set a pin faster than digitalWrite?

Yes there is! You can directly manipulate the port. The Arduino website has a pretty good explanation for it here. Togelling a pin as asked by you can be simply done by something like this: PORTB ^...
KarlKarlsom's user avatar
4 votes
Accepted

Interrupts: use of the "volatile" keyword with a structure pointer for button debounce

I think, that the problem is in ideb_read, which expects "a pointer to (non-volatile) structure" and so it does not care about re-reading ideb->output if it can it optimize out somehow (say putting ...
gilhad's user avatar
  • 1,420
4 votes

Interrupts: use of the "volatile" keyword with a structure pointer for button debounce

Getting pointer declarations right can be anything but obvious, especially where const and volatile are concerned (which are syntactically equivalent). Your problem stemmed from the confusion between "...
JRobert's user avatar
  • 15.3k
4 votes
Accepted

Arduino delay inside of an Interrupt

Why is putting a delay() inside of an ISR cause wonky behavior with the Arduino. Whats going on under the hood? The first problem is that delay() is a busy loop monitoring millis(). The value that ...
esoterik's user avatar
  • 628
3 votes

why does function affect my ISR?

This isn't the sort of approach you should use in an ISR. You need to get into the ISR, and get out of it ASAP. Set a flag, and read the flag in your code to decide what needs to be done. There ...
Scott Seidman's user avatar
3 votes

ATmega328p hangs on USART RX interrupt

I suspect if you were a fly you would see your LED flashing very very rapidly. The reason is, your interrupt will constantly trigger itself over and over and over again. Why? Because you aren't ...
Majenko's user avatar
  • 105k
3 votes

Difference between ISR and other functions in AVR twi library

The confusing thing is that there is only one interrupt, and it is called for a number of different reasons. To make sense of why it's being called you also have to know what you have just done in ...
Majenko's user avatar
  • 105k
3 votes

AttachInterrupt - fail to initiate inside a class

Firstly, if detection_door is a non-static member function, then C++ simply has no such expression syntax as just detection_door. Such functions have to either be called (with () operator) or be taken ...
AnT stands with Russia's user avatar
3 votes

Arduino Timer0 Piggyback

The Arduino core configures Timer 0 for a period of 1,024 µs. Your ISR will then be called at very regular intervals, and is a good place to have timing-related code. You just have to keep in ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

Why impedance between I/O pin and ground drops when Arduino is not powered

The Atmega328p (which is used in the Un[ (and actually all other AVR microcontrollers) has clamping diodes in the input hardware to protect it from overvoltage (above Vcc). When not powered, Vcc is at ...
chrisl's user avatar
  • 16.3k
3 votes

How do I temporarily disable TIMER5 Interrupts?

You wrote: TIMSK5 |= OCIE5A; You mean TIMSK5 |= _BV(OCIE5A); or, equivalently, TIMSK5 |= 1 << OCIE5A;
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

Is there anything wrong with this code

The only problem I can see is in your use of the counter variable. This is a volatile variable that is incremented in an interrupt routine and read from the main loop context. The variable is "...
Majenko's user avatar
  • 105k
3 votes

Is there anything wrong with this code

Here are some random comments from looking at the code. First issue, which is more about the example than the library itself: there is no Serial.printf() in the standard Arduino cores. Yes, it is ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

How do I properly use an ISR inside a class definition?

You have three different variables named stAng here: a static member of the Bike class, which has been declared but not defined, and is never used a local variable of the Bike::incStAng() method a ...
Edgar Bonet's user avatar
  • 43.3k
2 votes

How to user timer interrupts for times longer than can TNCTx can keep track of?

By maintaining your own second-level prescaler you can quite easily keep track of longer periods. The most efficient method is to use a "divide and multiply by two" scheme. Start with a custom pre-...
Majenko's user avatar
  • 105k
2 votes
Accepted

What is the maximum length an Interrupt Service Routine?

What is the maximum length an Interrupt Service Routine? This depends on the max latency before servicing any other waiting Interrupt Service Routine (ISR). An AVR ISR will execute with further ...
Mikael Patel's user avatar
  • 7,969
2 votes

What is the maximum length an Interrupt Service Routine?

As already explained by jwpat7, interrupts are, by default, not interruptible. Thus, if another interrupt fires while your ISR is running, it will no be serviced until your ISR completes. This delay ...
Edgar Bonet's user avatar
  • 43.3k
2 votes

What is the maximum length an Interrupt Service Routine?

In general, on AVR devices, interrupts have been turned off (by hardware) when an ISR (interrupt service routine) begins execution. Thus, if on_encoder_pulse() is an ISR and is invoked due to an ...
James Waldby - jwpat7's user avatar
2 votes

why does function affect my ISR?

I'm not very familiar with the details of the Arduino infrastructure either, but I think your fundamental problem is the fact that you are doing GPIO (i.e., digitalRead() and digitalWrite()) both in ...
Dave Tweed's user avatar
2 votes
Accepted

Can't operate relay's functionality in ISR function - SOLVED

Here is how I would do it: volatile uint32_t injTime = 0; void setup() { pinMode(13, OUTPUT); pinMode(2, INPUT); attachInterrupt(0, countRPM, FALLING); } void loop() { if ((injTime &...
Majenko's user avatar
  • 105k
2 votes

ISR and multiplexing- time required to execute the code in Arduino

(In a comment the asker mentioned they're not sure of the "usual approach", so I've provided this answer to hopefully help clarify) Here is my code for using a single 595 to drive the columns, and ...
redstarcoder's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible