0
\$\begingroup\$

I want to write a program that intercepts serial communication between two microprocessors. Therefore I chose the Atmega 162 featuring two UARTS. Now I want to decide if I write the code using interrupts (which makes things more compilacted)

or just in a cyclic way

  • read from UART
  • process data
  • write to UART

The packets are fixed size are 42 bytes on one line and 12 bytes on the other line. Between the single packets is a gap with ~1 ms.

The question: Do you agree to use the cyclic (fixed) way instead of interrupt driven way?

Theres no code up to now, but here you can find the project page

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

The answer to this partly depends on how much other processing is going on in the system, what processor it is and how fast the micro is running. If you were doing nothing but taking in serial data and mirroring it out then you'd possibly be fine.

However, if you are doing a load of processing and there is the slightest chance that before you come back to poll the UART more than one byte of data will have been received, then you have to have it done with interrupts.

I would argue that interrupts don't add that much complexity, writing to a buffer, filled in the interrupt service routine that is emptied and processed when the processor has time is not that complicated at all and regularly a vital part of embedded firmware.

I believe there are industries such as the nuclear industry and other safety-critical industries where interrupts are forbidden, but other than that they are a staple part of coding and well worth learning how to implement.

\$\endgroup\$
5
  • \$\begingroup\$ You mean, all interrupts are forbidden except for the timer? \$\endgroup\$ Commented Sep 12, 2017 at 10:46
  • \$\begingroup\$ There´s not much processing to do. Nevertheless I will implement a asynchronous way just to be safe I did it best I can :) \$\endgroup\$ Commented Sep 12, 2017 at 10:51
  • \$\begingroup\$ @DmitryGrigoryev Not sure in all honesty. I did a course on RTOSes a few years back and I remember the presenter talking about safety critical systems and how they were very conservative and wouldn't allow use of an RTOS or interrupts. I don't remember whether he specified timers are fine. It's entirely possible he did and I have forgotten in the mists of time. You may well have more knowledge on this than me :) \$\endgroup\$
    – DiBosco
    Commented Sep 12, 2017 at 10:51
  • \$\begingroup\$ I think in security critical environment you have to proof your code. IMHO this is only possible with functional languages. Events/Interrupts will break the ability to proof or at least make it harder. \$\endgroup\$ Commented Sep 12, 2017 at 10:53
  • \$\begingroup\$ @TomSchardt Timer interrupts are different from peripheral interrupts in that they don't occur at random, so you can still include them in your reasoning using temporal logic and similar concepts. But I've never worked in nuclear, so who knows - maybe they have a timer driver implemented using polling. \$\endgroup\$ Commented Sep 12, 2017 at 11:06
1
\$\begingroup\$

Interrupts will save you some CPU time which you'd otherwise spend busy-waiting. However if the MCU is not supposed to do anything besides pumping data between UARTS, you're going to waste that time anyway since there's noting else to do. So, if you're sure your MCU will only have this one task, you might as well program it to use polling.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.