2012-12-30 12:28 PM
I have been working on a program to directly transmit any character or set of characters that I transmit from the PC via UART, back to the PC immediately. This is just the first step in my project.
Code (this works):while(1) {
int8_t buffer[20]; scanf(''%s'', buffer); printf(''%s\n'', buffer); STM_EVAL_LEDToggle(LED4); } Next I want use the value I receive from the PC for some mathematical operations in 'float' data type. Can anyone please tell me how to covert the value received 'buffer' to a float value? 'Thank You' in advance. #tags-are-pointless #stm32f0-usart #lacks-specificity #connect-uart-to-pc2012-12-30 12:36 PM
Presuming you have a decent tool chain with libraries that support floating point, and more specifically floating point support in scanf/printf
float flt; sscanf(buffer,''%f'',&flt); Or double dbl; dbl = atof(buffer); Or you could do some decimal math and parse it yourself.2012-12-30 12:44 PM
2012-12-30 02:21 PM
Both of these methods give errors. I am going to try parsing.
Perhaps some specificity to the error, and the tool chain, might help arrive at a solution. atof() is usually part of stdlib.h, at least on Keil. I'd probably be including math.h and stdlib.h, along with stdio.h A quick Google would probably bring up source code for something like atof(), or a lightweight equivalent thereof.http://code.google.com/p/unladen-swallow/source/browse/branches/release-2009Q1-maint/Python/atof.c
2013-12-31 12:58 AM