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.

Problem with PC app reading from micro via serial comms

Status
Not open for further replies.

peeryus

New Member
Hello everyone

I'm making a temperature monitoring project and I want to display the measured temperatures on a GUI which I created using C#. The correct data is sent across when I view it in hyperterminal. However, C# is only reading the 1st 4 characters. The float value of the temperature is converted to an ASCII (using ftoa) and this ASCII value is sent across to the PC app. Any idea why the PC cant capture all the characters? But if I send across a pure string like "Hello" , it captures all the data perfectly.

Please help
 
Sounds like you're getting all the characters, but ftoa isn't converting as you expect. I'd suggest you go over the document for that function and make sure it makes what you expect.

Also, make sure you're sending a string to your port, and not a character.
 
Last edited:
Yeah maybe. Either that or the ASCII characters are large for some reason. Does anyone know of any other way of converting a float to string. Am i correct in saying that one character needs to be transmitted over USART at a time? Does ftoa indeed convert the float to character equivalents?
 
There cannot be a character that can represent a float. Make sure you're sending the entire target string. In other words, if you're using a function to send the ASCII, make sure it accepts a string, and not a char.
 
Last edited:
Thanks for the reply BrownOut

You see, my temperature measurements are float values. I don't know what conversions to do from here. What do u suggest? I convert the float to an ASCII so that I can display it on an LCD. I then send this ASCII value across but my USART_Transmit routine accepts only a character at a time. How do I make the USART_Transmit routine send a string across? I thought UDR can accept a character variable.

Thanks again
 
Hi

Because I thought it needs to have decimal values to be more accurate. I get values like 27.3, 25.4 etc. What do u advise I make it?
 
Thanks for the reply BrownOut

You see, my temperature measurements are float values. I don't know what conversions to do from here. What do u suggest? I convert the float to an ASCII so that I can display it on an LCD. I then send this ASCII value across but my USART_Transmit routine accepts only a character at a time. How do I make the USART_Transmit routine send a string across? I thought UDR can accept a character variable.

Thanks again

But you said you can send stings like "Hello" Or do you actually send that one character at a time? I don't know what your function looks like that you send characters with, but you might need to write you own, if you don't have on, that sends characters until it finds a null terminator.

send_ascii(string_value)
{
int i = 0;
do {
send_char = string_value(i);
i++;} while (send_char != "\0")
}

Where "send_char" is whatever buffer you write your character to that gets transmitted. Pardon my poor C syntax. YOu'll have to clean it up. It's been a long time...
 
Last edited:
Code:
      //Read data from serial port
      data=USARTReadChar(); 
      
      switch (data)
      {
                  
        case 'a' : {     
                     for (i=0;i<35;i++)
                        {
                            USARTWriteChar(send[i]);     
                        }
                    break;  
                   }

USARTReadChar gets a character from my PC app. It acts as a request. If it's a then it sends the string "send". All the characters are sent across as I can see them when I use hyperterminal. It's just getting lost on the PC side. Any idea how to change it to ANSI in the C# project?
 
Hey

I got it sorted. ftoa converts string to ASCII but the ASCII is in a string. When sending it across the serial comms, it has to be the exact length. For eg if the string is 10 characters long and the real data that u need are only in the 1st 4 characters, u have to send these 4 characters across only, not all 10. If u send all 10 across it causes sh!t.

I needed to send many strings across. So I made a new string and I appended each smaller string to this longer string. But make sure u append only the characters u need. Not the unnecessary ones. Oh and make your micro triggers an interrupt when it receives something. I send a request from my PC. This triggers the interrupt on the micro and then it sends across this new string to the PC. It's just more efficient this way. Yoh it was frustrating!
 
Anyways, now Im trying to send a string from my PC to my micro. The string starts with "c" so it can be identified. How do I receive a string on my micro? I know a character at a time but how? I have the receive interrupt enabled on my micro USART.

Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top