Use and print out floating point with K60 and codewarrior

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Use and print out floating point with K60 and codewarrior

926 次查看
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.

标签 (1)
0 项奖励
回复
4 回复数

562 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

562 次查看
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 项奖励
回复

562 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

562 次查看
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 项奖励
回复