RTX166 TINY: Using Printf, Sprintf, Scanf, and Sscanf
Information in this article applies to:
I have a very simple program that uses Round-Robin task scheduling and the printf function. Sometimes the output from sprintf and printf is corrupted as demonstrated by the following test code.
How can I solve this problem.
The RTX166 Tiny README.TXT file found in the \KEIL\C166\RTX_TINY\ folder describes that using pointers to stack-based variables is not safe.
The printf, sprintf, scanf, and sscanf library routines (as well as any other routines with variable-length argument lists) use pointers to access the parameters (which are passed on the stack). Since RTX166 may reorganize the stack after a task switch, you see the strange output results that you do.
The result is that any function which uses variable-length argument lists (like printf, scanf, and so on) will not work as expected.
We recommend that you disable the RTX Tiny Hardware Timer Interrupt for those routines that access the stack via pointer. For example:
Note that this problem does not exist with ARTX-166. So you may want to consider using ARTX-166.
Last Reviewed: Thursday, February 25, 2021
of your data.