ARM Technical Support Knowledge Articles

CALLING PRINTF IN AN INTERRUPT

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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.

Article last edited on: 2001-07-08 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential