2

I am completely lost on what to do with this issue. I'm not very familar with c language, but I know enough to program my Atmel MCU for a controls project. I'm running into an issue where I try to print double variables and all I get out are question marks instead of values. Here is some code:

axg = ax/MPU6050_AXGAIN;
ayg = ay/MPU6050_AYGAIN;
azg = az/MPU6050_AZGAIN;
gxds = gx/MPU6050_GXGAIN;
gyds = gy/MPU6050_GYGAIN;
gzds = gz/MPU6050_GZGAIN;

printf("converted\n\n");
printf(" %f;\n\n %f;\n\n %f;\n\n %f;\n\n %f;\n\n f;\n\n",axg,ayg,azg,gxds,gyds,gzds);

All the printed variables are defined as doubles. The ax,ay,ay,gx,gy,gz are all uint16_t variables. What I am doing is reading 8 bit data from an IMU and storing those values in ax,... etc. Then I need to convert them based of information in the datasheet of my IMU( MPU 6050 in case anyone is curious). Could anyone point me in a direction for trouble shooting this? Everything I have come across indicates that I should be getting values and I don't know where to look any longer.

thanks in advance.

here is my terminal read out

converted

?;

?;

?;

?;

?;

?;

Shivendra Mishra
  • 638
  • 4
  • 25

3 Answers3

2

It sounds like you are linking against a version of printf that does not have floating point support.

This is often the default configuration for compilers for embedded systems, because they don't have hardware FPUs and software floating point support uses precious space which most applications don't need.

Consult the documentation for the toolchain you are using to see if this issue is discussed. Link to similar thread for gcc/Arduino

Also consider whether your code can be rewritten to not use floating point.

Community
  • 1
  • 1
M.M
  • 138,810
  • 21
  • 208
  • 365
  • thank you that solved my issue. In atmel studio there is a configuration menu with a tab for toolchain. In that tab I went to AVR/GNU label in a tree with a general tab underneath it. In the general tab this is a box to check mark. – theschweizer May 26 '15 at 21:35
0

What I am doing is reading 8 bit data from an IMU and storing those values in ax,... etc.

I would prefer unsigned char for 8 bit data. And this question has an answer for printing uint16_t type of data: Format specifiers for uint8_t, uint16_t, …?

Tell us a bit more about environment you are running this code.

Community
  • 1
  • 1
Shivendra Mishra
  • 638
  • 4
  • 25
0

I had faced a similar issue while I was working on an AVR. As I was implementing it for debug purpose and the code snippet was not going to be a part of the actual source code, I didn't invest much into compiler and its optimization levels and other dependencies since it could have caused issue somewhere else had the optimization levels been changed. So this fix worked for me.

#include<stdio.h>
#include<string.h>

void foo(float fl_value, float fl_limit)
{
    char str[20];
    memset(str, 0, 20);
    sprintf(str, "%0.2f", fl_value);
    sprintf(str+4, " %0.2f", fl_limit);
    printf(str);
}

int main(void)
{
    foo(5.4, 10.8);
    return 0;
}
WedaPashi
  • 3,561
  • 26
  • 42