ARM Technical Support Knowledge Articles

TRANSMITTING FLOATING-POINT NUMBERS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

How can I send and receive floating-point numbers via the on-chip UART? I have tried using a printf/scanf combination, but I cannot get it to work.

ANSWER

A floating-point number is stored in memory using four bytes. A good way to transmit the number is to simply send those four bytes, using a pointer to access the bytes.

Here is an example:

float f = 4.7838322;

void main(void)
{
  unsigned char *ptr, i;

  ptr = (unsigned char *)&f;
  for (i = 0; i < sizeof(float); transmit(*(ptr + i)), i++);
}

where the function transmit is your custom function that transmits an unsigned char using the on-chip UART or whatever method/peripheral you choose.

To receive the floating-point number simply reverse the process, again using a pointer.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 13:16:04

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential