• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

convert characters received from UART to int and float in keil5 stm32

tariq70

New Member
hi
i receive my data from uart by this command :

HAL_UART_Receive(&huart1,data,10,1000) ;

my received characters are decimal numbers and i want to convert them to float and int then i send float or int as a character

for example my data is
data="32.54"
this data occupies 1 byte for each character so data occupies 5 bytes i want to convert it to float and then send float in my memory that requires less bytes than 5.
 
Each received character is ASCII. Check the ASCII table for values. You'll want to test each character, converting the numerals to an actual decimal value. "3" doesn't come over as 3, it comes over as its ASCII value (check the table!). If you want someone to write your function you're out of luck.
 

Pommie

Well-Known Member
Most Helpful Member
If you can send all values as integers then you can use atoi (). For floats you can multiply be 100 to keep 2 decimal places.

Mike.
 

Latest threads

EE World Online Articles

Loading
Top