32

I didn't read you document really, but I can understand why you are confused. But it is a very simple concept really. Let me explain. Triggering: This means making a circuit active. Making a circuit active means allowing the circuit to take input and give output. Like for example supposed we have a flip-flop. When the circuit is not triggered, even if you ...


24

Designing by rules of thumb you found on the internet someplace is a bad idea. The right way is to understand the issues, them make intelligent tradeoffs. There is nothing wrong with a system that takes a interrupt, clears the hardware condition, then sets a flag for foreground code to do the remainder of the processing when it gets around to it. The ...


24

Yes. Pretty much everything in an MCU can be interrupted by an interrupt request. When the interrupt handler completes the previous code will just continue so it is usually not a problem. In a special case the interrupt handlers can be interrupted themselves by interrupts of higher priorities (nested interrupts). If a series of instructions must not be ...


22

The vast majority of SPI devices will be perfectly happy at any data rate below the specified maximum. One could perform part of a transaction, take a break at any point, come back a few years later, and finish it. Provided that there were no glitches on the clock, select, or power lines, the transaction would be completed normally. There are three main ...


18

The first tactic is to architect the overall firmware so that it's OK for interrupts to occur at any time. Having to turn off interrupts so that the foreground code can execute a atomic sequence should be done sparingly. There is often a architectural way around it. However, the machine is there to serve you, not the other way around. General rules of ...


18

The main difference between a function and a software interrupt is what is known as context. A function runs within the context of your main program. An interrupt runs within the context of the interrupt handler. On a simple system this may be no real difference, and software interrupts may simply be used as a convenient way of providing library routines ...


16

If the question is about a bare AVR microcontroller, then no, there is no constraint on using any of the timers. For the Arduino, Timer0 is best avoided, as the millis(), delay() and all internal timekeeping in the Arduino libraries use this timer. Changing it's time constant will impact these operations. Timer1, as the question states, is the popular ...


16

The AVR is a RISC architecture, so it has pretty basic hardware handling of interrupts. Most processors mess with the stack during interrupts, though there are a couple, most notably ARM and PowerPC, that use different methods. In any case, this is what the AVR does for interrupts: When an interrupt occurs, the processor hardware does these steps, which ...


16

Yes, it's a good idea - the only downside is a bit of extra code size, and you have to decide what to do with the trap (emit a message on the serial port? turn on a "FAILED" light? Silently reboot? etc)


16

If there is no ISR defined, the location for the jump instruction in the interrupt vector will either be null, it may be a jump to an exception routine, it may jump to the beginning of the program, or it may contain a "return from interrupt" (e.g. RTI) instruction. Here is a disassembly of an interrupt table for an ATMega 16 processor showing three unused ...


15

Sometimes finding the answer to these questions for an ARM device can be more difficult than simpler microcontrollers because the information is often spread across family and programming guides rather than included in the datasheet. In this case the answer appears to be on page 381 of the RM0090 Reference manual: The STM32F4xx are able to handle external ...


14

The following information is in addition to Igor's excellent answer. From a C programming perspective, the interrupt handlers are defined in the cr_startup_xxx.c file (eg cr_startup_lpc13.c file for LPC1343). All possible interrupt handlers are defined there as a WEAK alias. If you do not define your own XXX_Handler() for an interrupt source, then the ...


14

Pin change interrupts are usually not a good way to detect button actions. This is because mechanical buttons bounce, and you will get lots of meaningless interrupts, and then you still have to do debouncing anyway. A better way is to have a periodic interrupt, like every 1 ms (1 kHz rate). That's a long time on most processors, so the fraction of time ...


14

Generally, you only need to handle the interrupt flags which you have specifically enabled with USART_ITConfig(). However, if you enable the RXNE interrupt (USART_ITConfig(USARTx, USART_IT_RXNE)) then this also enables the Overrun interrupt! So you must handle both of those. The USART flags can be confusing. There are separate status flags and interrupt ...


13

The most difficult part of handling a critical section without an OS is not actually creating the mutex, but rather figuring out what should happen if code wants to use a resource which is not presently available. The load-exclusive and conditional-store-exclusive instructions make it fairly easy to create an "swap" function which, given a pointer to an ...


13

What you are missing is that the core does do more than just execute opcodes that are fetched from memory. It has specific logic in it to implement interrupts. When the interrupt detection hardware asserts the signal that says it's time to take a interrupt, usually a special instruction is jammed into the core that was never fetched from memory. In most ...


13

My informal rule is: If an interrupt is enabled, then you should have code that handles it. If you don't write code for an interrupt, disable it. If you can't disable it, write code for it. Even without that rule, though, the data sheet explicitly answers your question: If the user does not intend to take corrective action in the event of a trap ...


13

A couple of definitions first: In the Cortex-M programming manual, an Exception is anything that breaks the normal program flow, and invokes a handler from the vector table, and Interrupts are a subset of Exceptions, coming from the peripherals outside the ARM core. Because SysTick is implemented in the Cortex-M core, it is considered an exception, but not ...


12

Others have already pointed out the original problem in the comments above, namely that you need to reserve space for the character array. I have made a few other changes to your original code, including: Allocate space for the character array Move code out of the interrupt service routine and back into main() Using a global flag to communicate between the ...


12

There is a de facto standard way to do this (assuming C programming): Interrupts/ISRs are low-level and should therefore only be implemented inside the driver related to the hardware that generates the interrupt. They should not be located anywhere else but inside that driver. All communication with the ISR is done by the driver and the driver only. If ...


12

There are two things wrong with your code: 1) you attempt to reset and restart the counter in the interrupt handler with "TIM1->EGR |= 0x01;" . But you're using the automatic reload mode of the counter so you shouldn't do that. 2) You never clear the interrupt from the timer. The timer sets the interrupt, but you're responsible for clearing it once you've ...


11

Set an output pin when you enter the ISR and clear it before returning from it. Filter the output with an RC filter. The voltage across the capacitor should give you the ISR duty cycle. For instance, if your power supply is 3.3V and you measure 33mV, then you spend 1% of the time in the ISR.


11

The Cortex M3 supports a useful pair of operations of operations (common in many other machines as well) called "Load-Exclusive" (LDREX) and "Store-Exclusive" (STREX). Conceptually, the LDREX operation performs a load, also sets some special hardware to observe whether the location that got loaded might be written by something else. Performing a STREX to ...


11

Checking a copy of the specification (which I can't quote for copyright / NDA reasons) the SPI rate is specified starting at 0Hz implying static operation is fine. Under SPI you only get data back while the device is being clocked, so if using a hardware SPI you'll only receive something after data (even if 0 / don't care) has been sent. So in that regard it'...


11

The conventional method for dealing with multi-byte receives in an interrupt routine is to setup a circular queue. As each byte is received it is placed into the next available slot in the queue. This would replace your single byte save code that you have now. The output side of the circular queue is polled for available content by your mainline code that ...


11

Software interrupts may be used to finish off an interrupt task at a lower priority. Timing critical code is often given a high interrupt priority to avoid too much latency. Once the timing critical part is finished, there may be additional tasks that may be too timing critical for the main loop, but are not so critical as to hold-up other high-priority ...


11

Never, never, never put file I/O in an interrupt routine - unless it is the only routine to do file I/O. And then still don't do it! An interrupt can interrupt anything: including file I/O. And interrupts should be quick, quick, quick! File I/O just isn't. You need to use the tickers to store the data in memory buffers, then write the data inside loop().


11

Any operation that is not atomic can be interfered with by an interrupt. This kind of programming is often very different than most other programming and can be confusing to people who haven't studied processor design or computer architecture. You may think to yourself "This will never actually happen, how long does this code take to copy and how likely is ...


10

(Please note that points 1 and 2 are implementation details and not architectural limitations.) In bigger NXP chips (such as LPC17xx) there are a couple of dedicated interrupt pins (EINTn) which have their own interrupt handler. The rest of GPIOs have to use one common interrupt (EINT3). You can then poll the interrupt status register to see which pins have ...


10

Noah Stahl's blog has an example of blinking a LED with Timer2. With that and the data sheet, you should be able to adapt it to whichever interrupt you want to use -- i.e., the interrupt whose normal function you can most afford to give up or are willing to modify. Timer2 is usually used for some PWM functions. His example cites the ATmega2560; I can ...


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