This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Energia+CC3200-LAUNCHXL: sprintf weirdness

Other Parts Discussed in Thread: CC3200, ENERGIA

I have a rather large sketch in Energia for the CC3200 LaunchXL. Sometimes sprintf does weird things.

For example,this code...

  char buffer[500];
  sprintf(buffer, "%f, %f, %f, %d", 1.0, 2.0, 3.0, 4);
  Serial.println(buffer);

produces this result:

0.000000, 0.000000, 0.000000, 536966100

That seems incorrect to me. There seems to be a pretty significant bug in the Energia+CC3200 implementation of sprintf. It seems like it might be related to either global memory size or current stack usage, though I can't find an exact pattern.

Any ideas for how to fix this?

  • Hello,

    Just tested your code on CC3200 SDK (not energia) and it works fine.

    I am looping Energia expert for feedback.

    Regards,

    Shlomi

  • Yes, it worked great with a small sketch. After adding lots of other code in the sketch (reading sensors via i2c, WiFi client, flash file access, etc.) then at some point it stopped working. I've tried re-factoring to reduce memory usage, but that didn't help. Everything else in the sketch works fine (even demanding functions that use a WiFi client), but this bit of code does strange things.

    Unfortunately, I can't post the whole sketch, since it contains proprietary intellectual property. And I haven't been able to replicate the problem in a clean-room environment, since I'm not sure exactly what the trigger mechanism that causes it to fail instead of succeed.

    Note this problem also happens with snprintf.

    I've also tried using the String C++ class, but that suffers from similar problems. For String C++, the primary problems occur when converting floats into Strings. The floats end up usually as 0.00000 or sometimes as seemingly-random numbers. With sprintf and snprintf, integer conversion also seems messed up.