Hello Isabel:
printf(), sprintf() functions and the like consume a considerable time. If you have watchdog enabled this may be causing your MCU to reset. Do you have it enabled? If so, you need to make sure that refresh period is longer than the duration of the sprintf() function itself.
Hope this helps!
Regards!
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------