Keil Logo

C51: CALLING PRINTF IN AN INTERRUPT


Information in this article applies to:

  • C51 Version 5.50

QUESTION

Is it safe to call printf() inside my CAN Interrupt Service Routine (ISR)? I want to do this so that my application will send back state information to aid debugging.

ANSWER

printf() should work inside the CAN ISR however this will introduce many areas for potential problems.

printf() is not reentrant so unless interrupts are disabled while calling it, it cannot be called from main code or from any other interrupt that does not have the same priority as the CAN ISR. In addition, it can never be called from the serial ISR. The library code for printf() is large (about 1kb) and slow to execute. This will dramatically affect the performance of your ISR and therefore your application. In addition it may adversely affect the behavior of your application.

If you wish to display state information then you have other options. For example changing the state of I/O pins or (if you are using tScope) putting the state in an xdata variable and watching the value.

Last Reviewed: Sunday, July 8, 2001


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.