This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Data transmission for float variables by uart0

hi everyone

I'm looking for a good alogrithm to send a float variable to a PC by the serial port.

First I have to separate the float variable in bytes to be read to send by the serial port. do i have to send the variables in binary or ascii?? what do you recommend me??

Another problem is in the pc.. if I want to use visual basic to print the value how can I join the bytes to have the real float variable??


thanks

Parents
  • "Another problem is in the pc.. if I want to use visual basic to print the value how can I join the bytes to have the real float variable??"

    No idea! :-(

    This is a Keil forum, not a Microsoft and/or VB forum - so you'll have to read your VB documentation, visit MSDN, and/or find a VB forum for that one.

Reply
  • "Another problem is in the pc.. if I want to use visual basic to print the value how can I join the bytes to have the real float variable??"

    No idea! :-(

    This is a Keil forum, not a Microsoft and/or VB forum - so you'll have to read your VB documentation, visit MSDN, and/or find a VB forum for that one.

Children
  • Can't help you with the VB, but here is a method that works great for uC to Labview over a serial port. Consider the following code snippet

    union {
    float floater;
    unsigned char string[4];
    unsigned long int longinter;
    unsigned int interger;
    } float_char;
    char sendbuf[4];
    float_char.longinter=MS_COUNTER_REF;
    sendbuf[0]=float_char.string[0];
    sendbuf[1]=float_char.string[1];
    sendbuf[2]=float_char.string[2];
    sendbuf[3]=float_char.string[3];
    UART0_Xmit(sendbuf, 4);//send 4 bytes

    float_char.floater=neon_pressure;
    sendbuf[0]=float_char.string[0];
    sendbuf[1]=float_char.string[1];
    sendbuf[2]=float_char.string[2];
    sendbuf[3]=float_char.string[3];
    UART0_Xmit(sendbuf, 4);

    end of code


    This results in sending out 4 bytes that make up a 32 bit floating point number. In labview, they have a unflatten from string function with will decode from 4 element string to 32 bit floating point. If VB has something equivilent, this may work for you. Hope this helps

    AC

  • Hi AC

    I'm very interested in the code for labview can you tell me your email. because I need to graph some value from my microcontroller.

    please help me thanks

  • You might want to take a look at http://www.windmill.co.uk

    They have loads of stuff (including free stuff) for getting serial data into Excel, and other PC things

  • Jean Paul,
    You can reach me at acurda@amsuper.com

    I can give you an example of converting such data to a floating point in labview if you need. I can try to help with other stuff if yo have specific question, but sometims this darn work thing gets in the way.

    Andy

  • Jean Paul,
    I sent you some examples but got another email from you. What country are you in anyway? You should of recieved 2 emails from me by now. Let me know here if you havn't recieved any email from me.

    Andy

  • Hi,
    My name is Claudio from Argentina.
    I had the same problem, but the microcontroller I'm using is a PIC 16F876.

    What I did was to use this article in the Microsoft Knoledge Base, were I could get the individual bytes of a VB long type variable:

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q171652

    This same works for single, or double floating point real types, so you can change the individual bytes with the ones received from the UART.

    I hope this would help.