Floating point value

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

Floating point value

974 Views
chetan98
Contributor II

I'm using Kw45 sdk example, for KW45 board I'd like to print the Floating point accelerometer values to the terminal using shell I also tried.

sprintf(str,"%f");

printf("%s",str);

IDE using MCU expresso 

But using printf or sprintf it is not printing even decimal value.

Thanks

Chetan

Labels (1)
0 Kudos
Reply
3 Replies

856 Views
chetan98
Contributor II

Hello Happy Diwali,

I am using Kw45 wireless uart and I want print value with 3 precision after point.

For eg 300.645 

Thanks 

Chetan 

0 Kudos
Reply

774 Views
sofiaurueta
NXP Employee
NXP Employee

Hello @chetan98 ,

 

Similarly to the ble_shell example, in the wireless_uart example, values are printed to the terminal using Serial_PrintDec function, which internally calls FORMAT_Dec2Str to convert integers into strings. See fsl_format.c for the conversion process:

 

/*Convert a uint32 to string*/

uint8_t *FORMAT_Dec2Str(uint32_t num)

 

Using this function as reference, you could implement a function to convert floating-point values to strings through a division-based method (split the float into its integer and decimal parts, convert each part to a string separately, and then combine them with a decimal point in between).

 

Best Regards,
Ana Sofia.

0 Kudos
Reply

945 Views
luis_maravilla
NXP Employee
NXP Employee

Hello Chetan,

Could you help us confirm what example are you using and for which SDK version please?

In the [ble_shell] example from the KW45 SDK, values are printed to the terminal using the function [SHELL_PrintfSynchronization], which is defined in [ble_shell.h].

To print integer values, the SDK uses [shell_writeDec], which internally calls [FORMAT_Dec2Str] to convert integers into strings. This conversion process is implemented in [fsl_format.c].

Using this approach as a reference, you could apply a similar method to convert floating-point values to strings and send to terminal.

 

Hope this information work for you.

Best Regards

Luis

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2187694%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFloating%20point%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2187694%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI'm%20using%20Kw45%20sdk%20example%2C%20for%20KW45%20board%20I'd%20like%20to%20print%20the%20Floating%20point%20accelerometer%20values%20to%20the%20terminal%20using%20shell%20I%20also%20tried.%3C%2FP%3E%3CP%3Esprintf(str%2C%22%25f%22)%3B%3C%2FP%3E%3CP%3Eprintf(%22%25s%22%2Cstr)%3B%3C%2FP%3E%3CP%3EIDE%20using%20MCU%20expresso%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20using%20printf%20or%20sprintf%20it%20is%20not%20printing%20even%20decimal%20value.%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EChetan%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2187694%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EFreedom%20Development%20Platform%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2194492%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Floating%20point%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2194492%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F249367%22%20target%3D%22_blank%22%3E%40chetan98%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ESimilarly%20to%20the%20ble_shell%20example%2C%20in%20the%20wireless_uart%20example%2C%20values%20are%20printed%20to%20the%20terminal%20using%20Serial_PrintDec%20function%2C%20which%20internally%20calls%20FORMAT_Dec2Str%20to%20convert%20integers%20into%20strings.%20See%20fsl_format.c%20for%20the%20conversion%20process%3A%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%2F*Convert%20a%20uint32%20to%20string*%2F%3C%2FP%3E%0A%3CP%3Euint8_t%20*FORMAT_Dec2Str(uint32_t%20num)%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EUsing%20this%20function%20as%20reference%2C%20you%20could%20implement%20a%20function%20to%20convert%20floating-point%20values%20to%20strings%20through%20a%20division-based%20method%20(split%20the%20float%20into%20its%20integer%20and%20decimal%20parts%2C%20convert%20each%20part%20to%20a%20string%20separately%2C%20and%20then%20combine%20them%20with%20a%20decimal%20point%20in%20between).%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3EAna%20Sofia.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2192295%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Floating%20point%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2192295%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20Happy%20Diwali%2C%3C%2FP%3E%3CP%3EI%20am%20using%20Kw45%20wireless%20uart%20and%20I%20want%20print%20value%20with%203%20precision%20after%20point.%3C%2FP%3E%3CP%3EFor%20eg%20300.645%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3CP%3EChetan%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2187836%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Floating%20point%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2187836%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20Chetan%2C%3C%2FP%3E%0A%3CP%3ECould%20you%20help%20us%20confirm%20what%20example%20are%20you%20using%20and%20for%20which%20SDK%20version%20please%3F%3C%2FP%3E%0A%3CP%3EIn%20the%20%5Bble_shell%5D%20example%20from%20the%20KW45%20SDK%2C%20values%20are%20printed%20to%20the%20terminal%20using%20the%20function%20%5BSHELL_PrintfSynchronization%5D%2C%20which%20is%20defined%20in%20%5Bble_shell.h%5D.%3C%2FP%3E%0A%3CP%3ETo%20print%20integer%20values%2C%20the%20SDK%20uses%20%5Bshell_writeDec%5D%2C%20which%20internally%20calls%20%5BFORMAT_Dec2Str%5D%20to%20convert%20integers%20into%20strings.%20This%20conversion%20process%20is%20implemented%20in%20%5Bfsl_format.c%5D.%3C%2FP%3E%0A%3CP%3EUsing%20this%20approach%20as%20a%20reference%2C%20you%20could%20apply%20a%20similar%20method%20to%20convert%20floating-point%20values%20to%20strings%20and%20send%20to%20terminal.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EHope%20this%20information%20work%20for%20you.%3C%2FP%3E%0A%3CP%3EBest%20Regards%3C%2FP%3E%0A%3CP%3ELuis%3C%2FP%3E%3C%2FLINGO-BODY%3E