Jump to content
CodilX

Serial communication somewhat broken?

Recommended Posts

Hi there,

 

I'm trying to create a sort of CLI for the LaunchPad via Cygwin on Windows. Basically I'm trying to create different "programs" on the LaunchPad, and display the results on a LCD I have coming. For the time being, for development purposes I'm just using the serial com to emulate the output.

 

My goal is to have a few programs, such as display number of new emails, show current PC down/up speed, PC sensor readings etc, and being able to navigate through them via the input button on the LaunchPad.

 

To do so, I need serial input/output. I need the LaunchPad to send a request to my PC, such as, receive number of new emails, get the output and display it on the LCD (serial com for now).

 

It almost works perfectly, just I have an issue with the characters. Sometime the characters get messed up, and the commands are thus broken. Is this due to actual ascii characters being sent? Maybe I have to reset the onboard memory to free space for the receiver? Here's my code for testing the input and displaying what was received. I guess it has something to do with the input being sent/received, as if I add a check if(Input == "some command") { Serial.println("This command was received!"); } It doesn't always display this message, as you can see by the output - it sometimes receives gibberish.

 

String Input = "";    // string to hold input

void setup() {
 Serial.begin(9600);
 Serial.println("Enter Input");
}

void loop() {
 while (Serial.available() > 0) {
   int Receiver = Serial.read();

   Input += (char)Receiver; 

   if (Receiver == '\n') {
     Input.replace("\n", "");
     Serial.println(Input);
     Input = ""; 
   }
 }
}

I then send a series of test strings - test; lorem; ipsum; qwerty; launchpad - each of them 3 times. My output is attached below.

 

Also a quick question, how do I enable sending characters through Putty? I can view the output just fine, but I can't enter anything.

 

Thanks.

post-45469-135135570248_thumb.jpg

Share this post


Link to post
Share on other sites

Thank you. So for the time being I guess there is now way to fix this, and just wait for the update?

 

Also, if anyone could help me get PuTTY working with the LaunchPad would be awesome. I've seen a bunch of videos of people being able to do so, but they're using CCS to write and compile their programs, so is this issue of not being able to send commands to the LaunchPad in any way related to it being compiled by Energia?

 

I've just checked, that commands sent from PuTTY actually get received, but in a weird way. If I enter a string in the PuTTY terminal, press enter, close PuTTY, reopen the Energias COM tool and send something, I will receive what was written in PuTTY along with the newly inputted text. To me this seems like a communication error? If I open Energias COM tool, write something and send it, then close the tool, reopen and do the same thing - I never get the previous lines submitted. So as far as I understand a newline isn't sent, or isn't correctly interpreted by the LaunchPad?

Share this post


Link to post
Share on other sites

The minimal libc that comes with mspgcc does not implement realloc. In the current release there is a bug in which realloc was erroneously replaced by malloc. I have put in a quick and dirty fix for this to work around this until libc gets realloc implemented. The patch is here: https://github.com/energia/Energia/comm ... 0c977c680f

 

--- a/hardware/msp430/cores/msp430/WString.cpp
+++ b/hardware/msp430/cores/msp430/WString.cpp
@@ -140,6 +140,7 @@ unsigned char String::changeBuffer(unsigned int maxStrLen)
       char *newbuffer = (char *)malloc(maxStrLen + 1);

       if (newbuffer) {
+               strncpy(newbuffer, buffer, len);
               free(buffer);
               buffer = newbuffer;
               capacity = maxStrLen;

 

In the file hardware/msp430/cores/msp430/WString.cpp around line 143 just under "if (newbuffer) {" add "strncpy(newbuffer, buffer, len);"

 

Robert

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...