Continue to Site

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.

  • 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

Status
Not open for further replies.

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.
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top