Qualcuno mi sa dire perchè non va questo protocollo seriale ?

Ho scaricato questo codice da internet ma a me sembra non funzionare.
Dal pc invio !100*
Sullo sniffer seriale vedo !1100*
Ma arduino non processa il messaggio.
Praticamente sembra che non entri mai dopo il while !!

Uso arduino mega con max232 e ricevo sulla porta1 e visualizzo i messaggi sulla porta0
Grazie per l'aiuto

Alverman

Questo il codice:

/*===========================
TITLE: Serial Echo Code v1.1
AUTHOR: Fayaz Kadir
DESCRIPTION: If you send a string starting with "!" and ending with "*", the Arduino responds back with "$Y" for valid data string, or $N for invalid data string. You can modify this code for your use.
COMPATIBLE BOARD: Arduino Mega (but any other Arduino should work fine)
============================*/
char string[25];
int i=0;
int string_len;
int inByte;
int last_inByte;

void setup() {
  Serial1.begin(9600); //INTIALISING THE SERIAL PORT
  Serial.begin(9600); //INTIALISING THE SERIAL PORT
}

void loop()  // LOOP FUNCTION
{
  inByte = Serial1.read();
  string_len=0;
   if (inByte == '!') read_serial();  // If Start of line ("!") is found, call read_serial() function
}

void read_serial()  // FUNCTION FOR READING THE SERIAL MESSAGE
{
   Serial.println ("SOL FOUND and reading");  // THE SOL (Start of Line) found notice.
   Serial.print("READ : !\n");  //Saying that it has read "!" on the serial port
   while (inByte != '*') // As long as EOL not found, keep reading
     if (Serial1.available() > 0) // if new data is available
          { 
            inByte = Serial1.read(); // Read new byte
            Serial.print("READ : "); // Display the new byte
            string[string_len] = inByte; // Save the data in a character array
            Serial.println(string[string_len]); // Print the characters that was recieved
            string_len++;}
      else if (Serial1.available() == 0)
            {Serial.println("EOL not available, data string invalid"); // If EOL not in the string
            Serial1.println("$N"); //FAIL SIGNATURE
            break;
            }
 if (inByte == '*')
  {
       Serial.println ("eol FOUND, and full string was");  // Echoes Success Message
       Serial1.println ("$Y"); //SUCCESS SIGNATURE
       for (i=0;i<(string_len-1);i++) Serial.print(string[i]);
       Serial.print ("\n");
   }
 }

C'era un break di troppo !!

Senza quello sembra funzionare

Però se tolgo il break quando non arriva il carattere di chiusura mi va in loop :frowning:

Scusate se insisto ma a voi funziona ?
Io provandolo così com'è anche con il monitor dell'ide non funziona !!

Vi linko da dove da dove l'ho scaricato.
http://fayazkadir.com/blog/?p=2291

Ho capito !!

Hai fatto tutto da solo :grin:

Già ..... aiutati che .........

XD