Keil Logo

C166: sprintf Converts Float Variables to Zero?


Information in this article applies to:

  • C166 All Versions

QUESTION

Whenever I try to format a Float variable using SPRINTF, the resulting string is zero. The values to be converted are within the floating-point limits. This only happens when I use my own startup code. What could be causing this?

ANSWER

You are not initializing the DPP1 and DPP2 registers in your startup code. Although your program does not use them, the C compiler requires that these registers are initialized during start up.

We strongly urge you to use the START167.A66 or START_V2.A66 file that we provide as the basis for your startup routines. The Keil startup code performs the following operations:

  • Clears DATA and optionally PDATA and XDATA memory,
  • Sets up the reentrant stacks (if necessary),
  • Initializes C Global Variables,
  • Initializes the DPP registers,
  • Defines and sets the main register bank,
  • Sets the Stack Pointer,
  • Jumps to your MAIN C function.

Your startup code must do all of these. If it doesn't, you may encounter run-time problems that are difficult to debug and diagnose.

MORE INFORMATION


Last Reviewed: Thursday, February 25, 2021


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.