SerialEvent not called?

Discussion in 'Arduino IDE' started by mbianco, May 14, 2015.

  1. mbianco

    mbianco New Member

    Joined:
    May 14, 2015
    Messages:
    1
    Likes Received:
    0
    Ignore this message... After a full day and night I realized what was going on...
    Sorry for the noise.


    I'm trying to program UDOO to exchange messages through serial port. I'm using serialEvent but something puzzling happens.
    When I connect the external computer to the CN6 (J18 unplugged) the program works only from time to time (actually quite rarely). Most of the time I got the HB (hearth beat) signal on the console but nothing else. Sometime I can enter the serialEvent (I see the message back on the console), but the program does not enter the while loop there. Same thing seems to happen also when I plug J18 back and use serial monitor from the UDOO arm processor... This code (the attached one is a snippet) works perfectly on Arduino Uno.

    Is there something I'm doing wrong with the jumpers, speed, whatever... Any advice would help greatly.


    Code:
    #include <circular_buffer.h>
     
    int loopcount = 0;
    
    void setup() {
      // initialize serial:
      Serial.begin(9600);
      delay(2000);
      Serial.write("Setup Completed\n");
    }
    
    circular_buffer incoming_buf;
    circular_buffer outgoing_buf;
    
    void serialEvent() {
      Serial.write("Something received\n");
      while (Serial.available()) {
        incoming_buf.insert(Serial.read());
      }
    }
    
    void send_msg() {
      char c = outgoing_buf.extract();
      while ( (c != '\n') && (c <= 127) && !outgoing_buf.empty()) {
        Serial.write(c);
        c = outgoing_buf.extract();
      }
      Serial.write('\n');
    }
    
    
    void loop() {
      loopcount = loopcount+1;
      if (loopcount == 500000) {
        Serial.write("HB\n");
        loopcount=0;
      }
    
      if (incoming_buf.messages()) {
        Serial.write("Received something\n");
        char c = incoming_buf.extract();
        int channel;
        switch (c) {
        case test_msg:
          Serial.write("Ok!");
          break;
        case '\n':
          break;
        default:
            signal_error(7);
          break;
        }
      }
    }
     
    Last edited: May 15, 2015

Share This Page