Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Tiva Serial.parseFloat/Int hang

$
0
0

Hi folks,

 

I am trying to figure out why the following code does not work on Tiva Launchpad with latest energia 0012, while it works perfectly on all MSP430 devices.

 

Example setup is as follows:

PC sends via UART "A 0\n" or "A 0 10\n". The code should parse this and return 0 and/or 10 values.

 

Sending "A 0\n" works fine, the number is parsed correctly. Sending "A 0 10\n" causes a hang on parsing the second number.

 

The solution to this problem is addind a delay of 1ms, which is quite a waste. Since it works otherwise, this potentially shows there is a bug somewhere. Can someone please confirm my findings.

void setup()
{
Serial.begin(115200);  
}

void loop()
{
  while (Serial.available() > 3) {
    int x = 0;
    float v = 0;
    // Check for "A " string
    if(Serial.find("A ")){
      // parse command number after space
      x = Serial.parseInt(); 
      delay(1); // THIS DELAY MUST BE HERE FOR THIS TO WORK ON TIVA
      if (Serial.read() == '\n'){
        // print
        Serial.print(x);
        Serial.print(" ");
      }
      //if not terminated, read the next number
      else{
        v = Serial.parseFloat();
        Serial.println(v);
      }
    }
  }
}

Viewing all articles
Browse latest Browse all 2077

Trending Articles