Use and print out floating point with K60 and codewarrior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use and print out floating point with K60 and codewarrior

854 Views
broccolee
Contributor III


Hi,

I'm using the Kinetis K60 towerboard (PK60DN512Z) and codewarrior 10.5. I am running the i2c example code, which prints out the accelerometer measurements. I would like to convert that to floating point value. Does anybody know how?

Thanks.

Labels (1)
0 Kudos
4 Replies

490 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Please check the attachment, it was modified from KL25' demo code, and can printf floating point number in 6 bit precision, also you can change it by adjusting the parameter-precision=n. !

Wish it can help you.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

490 Views
broccolee
Contributor III

Hi Jeremy,

Thanks for your help! I replaced everything in printf.c with what you sent, it works for the most part. However, it fails to print out negative floating points. See the screenshot below: (the values in the last column is the converted gravity values in floating point of the raw data, which is signed char in the third column, all negative values are displayed wrongly..). Any idea how I can troubleshoot this?

pastedImage_0.png

I have also attached my code for your review. It is actually example code for Kinetis K60 MCU, I modified it a little. Thanks.

0 Kudos

490 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

I'm still investigating the printf.c file now, so I'd highly recommend that you can use the some software tricks to convert the negative float variable into the positive, then use the codes likes below to plus the flag "-".

printf("-%f\r\n", float variable);

Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

490 Views
broccolee
Contributor III

Thanks for the suggestions! Would prefer that printf does it automatically for me. This'll do for now. Please let me know when a proper fix is discovered.

Thanks.

0 Kudos