Keil Logo

GENERAL: CALLING PRINTF FROM AN INTERRUPT


Information in this article applies to:

  • C166 Version 4.05
  • C251 Version 2.14
  • C51 Version 6.01

QUESTION

Are there any reasons why I shouldn't call the printf function from within an interrupt?

ANSWER

There are numerous good reasons to avoid calling printf from an interrupt routine.

Interrupt routines are typically used to respond to events that occur quickly. For this reason, it is usually important that interrupt service routines run fast. The printf function is not a fast routine. Especially if you consider that the output from printf may output to the slow serial port. At 1200 baud, a 100 character string takes almost 1 second to send. The printf function will therefore take more than that to execute. In this case, your interrupt service routine will take around 1 second to execute. If that interrupt happens faster than once per second, you will lose interrupts.

Last Reviewed: Wednesday, May 24, 2000


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.