10 votes
Accepted

Alternative to polling interrupt flag from main loop?

If the task is pretty short and time sensitive, your best option is to put it in the interrupt handler. If the task is big and not too urgent (like: it could well wait for a millisecond or so), your ...
Edgar Bonet's user avatar
  • 43.1k
7 votes
Accepted

Pin Change Interrupt Flag timing on 1284P

When it is entered. The wording is slightly vague but I think "when the interrupt routine is executed" means the commencement of execution. Otherwise multiple pin-change interrupts could be ...
Nick Gammon's user avatar
  • 38.2k
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.1k
3 votes

interrupt from a button and wait until serial port 1 has a message

chrisl's answer brings many excellent points, and I highly recommend you study it in detail. There are just a few points I would personally add or amend: an ISR should probably not last more than a ...
Edgar Bonet's user avatar
  • 43.1k
3 votes
Accepted

interrupt from a button and wait until serial port 1 has a message

The thing is: Inside an ISR (Interrupt Service Routine) not only does time measuring with millis() not work, delay() also won't work (it uses the same interrupt mechanism as millis() in the background)...
chrisl's user avatar
  • 16.3k
3 votes

Alternative to polling interrupt flag from main loop?

Since you tagged it Teensy: You could also reduce the priority of the interrupt, so that it can be interrupted by higher priority interrupts. Thus you can implement interrupts with longer durations ...
luni64's user avatar
  • 261
3 votes
Accepted

Timer interrupt setup for one second is too slow (~ 4 seconds)

There is a flag in TCCR1A/B called WGM12 which sets the wave generation mode (WGM) to Clear Timer on Compare Match (CTC). This causes the timer to count up to the value in OCR1A and then automatically ...
maddes8cht's user avatar
2 votes

How to make the built-in LED blink with a frequency of 5 Hz using interrupts

On the Uno (ATmega328P microcontroller), timers 0 and 2 are 8-bit only: they cannot count beyond 255. Timer 1, on the other hand, is 16-bits. This is the most convenient timer for generating low ...
Edgar Bonet's user avatar
  • 43.1k
2 votes

Using interrupts as flags/latches without any ISR

I'm not sure wrapping the long-running task in noInterrupts()/interrupts() is a choice ... That's right. Turning off interrupts would stop the timing/delay working so you wouldn't be able to time ...
Nick Gammon's user avatar
  • 38.2k
2 votes

How to use Interrupt in Arduino to receive the data from Serial Input

Why do you want to use an interrupt anyway? The serial hardware already generates an interrupt, and inside that ISR the incoming byte is placed into a buffer. I presume you have a main loop where you ...
Nick Gammon's user avatar
  • 38.2k
2 votes

Running ADC triggered by TIMER1_COMPB

Timer1 CTC mode requires you to put the CTC TOP value in OCR1A (see Table 15.5 in 328P datasheet). You didn't, so the timer is running all the way from 0 to 0xFFFF. Timer1 ADC trigger mode requires ...
Iris Artin's user avatar
2 votes

Timer interrupt setup for one second is too slow (~ 4 seconds)

It is ignoring this OCR1A = 15624; and simply rolling over at 65535 instead., hence the error factor of 4. You have to set the wave generation mode as CTC in registers TCCR1A/B.
6v6gt's user avatar
  • 1,053
2 votes
Accepted

Rising and falling edge on GPIO_STM32G4

I do not know how to use the HAL API you are using. I will instead suggest an approach based on the Arduino API, which is more suitable for this site. Take note of the current time on every transition ...
Edgar Bonet's user avatar
  • 43.1k
2 votes

Arduino interrupt for serial data on digital pin, that is too large for the serial buffer

GPS is a really slow communication, it communicates in 9600bps and data only available once in every second. Any MCU running at much slower than an Arduino Uno running at 16MHz should be able to ...
hcheung's user avatar
  • 1,381
2 votes

I can't get my interrupt to control my project

You are probably doing too much in your interrupt routine (ISR). See my answer here about using interrupts. I also have material on my web site which may be helpful. A comment you linked to https://...
Nick Gammon's user avatar
  • 38.2k
2 votes

Fixing a pedestrian traffic light sequence pattern in a cycle using millis and without delay

Here is some simplified example code that might be useful to you. It keeps the logic and the LED control separated by the use of flags. Simulation is at https://wokwi.com/projects/389132610627050497 /...
jsotola's user avatar
  • 1,515
1 vote

Emulating Arduino Uno with QEMU: interrupts do not work

The documentation of qemu-system-avr says: [...] ATmega controller, which model is limited to USART & 16-bit timer devices, enough to run FreeRTOS based applications [...] It means the emulator ...
1 vote
Accepted

I can't get my interrupt to control my project

I resolved my problem by following the guidance that I linked to from digikey. My solution: /* Sub Menu https://lcdmenu.forntoh.dev/examples/submenu */ #include <ItemSubMenu.h> #include <...
TheCodeGeek's user avatar
1 vote
Accepted

I cannot resolve the errors with attachInterrupt() (error: invalid use of non-static member function)

The solution is covered in my post here. However, to avoid link-only answers, the brief explanation is that a class method has a hidden argument "this" which refers to the instance of the ...
Nick Gammon's user avatar
  • 38.2k
1 vote

Wake esp8266 from deep sleep with PIR but disable while running code

Hi I have being using the circuit below now for a few weeks and all seems to work. When I wake from deep sleep I set the Latch pin to 0 to prevent any more resets. I do the work, I check if there is ...
Eoin Byrne's user avatar
1 vote
Accepted

Where to find interrupt flag for 3rd-party Arduino board cores?

the rising or falling edge flag is triggered prior to a rising or falling edge technically occurring before a pin is pulled high/low and the microcontroller "remembering" that event occurred,...
Nick Gammon's user avatar
  • 38.2k
1 vote

Using Internal Timer Interrupt to Read Analog Sensor

First, read Nick Gammon's answer: all his points are perfectly valid. He notes that the serial prints can be quite slow. And indeed, as I counted the characters, I find that the prints should take at ...
Edgar Bonet's user avatar
  • 43.1k
1 vote

Changing SPI ports on an Arduino

My second answer ... Your question, in bold, is a good example of an XY Problem. You asked: Is there any way to change the MISO line from 12 to 3, or will I have to resort to using Pin change ...
Nick Gammon's user avatar
  • 38.2k
1 vote
Accepted

Changing SPI ports on an Arduino

I have read that for Hardware interrupts, only pins D2 and D3 can be used to generate interrupts The pin-change interrupts, available on all pins of the Arduino Uno, are almost as good. I say "...
Nick Gammon's user avatar
  • 38.2k
1 vote
Accepted

Why NEC IR remote control decoder does not work

External interrupt version of NEC protocol decoder using micros() for timing instead of Timer 1. Drops NEC repeat codes, Otherwise, in the style of the code in the question. volatile boolean nec_ok = ...
6v6gt's user avatar
  • 1,053
1 vote
Accepted

How can when the button is clicked to display its name

The function pulseIn() has this comment in the source code: "This function performs better with short pulses in noInterrupt() context" see: https://github.com/arduino/ArduinoCore-avr/blob/...
6v6gt's user avatar
  • 1,053
1 vote

attachInterrupt has no effect on Industruino SAMD21

Industrial level I/O on Industruino, which includes CH1, CH6 and CH7 I tried, is not connected directly to the microcontroller. It uses a buffer and communicates through I2C in pull mode. That's why ...
Paul Jurczak's user avatar

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