SparkFun Forums 

Where electronics enthusiasts find answers.

Topics pertaining to the Arduino Core & software used with the Artemis module and Artemis development boards.
By YellowFlower
#225952
Hi Everyone,

Hope we are all well!

I am trying to figure out how to implement the serial interrupt in either Arduino or the HAL language. for the Redboard Artemis Nano

I can find the examples on Arduino for general interrupts and for Serial communications, but not for what would essentially be "Serial.event()" in your traditional Arduino coding.

If anyone can help out, that would be really appreciated!

Cheers,
YF
By paulvha
#225953
That Apollo3 code does not have this option.

In Arduino's main.cpp, as part of the never-ending loop, it has a check added for the "serialEventRun' mechanism. If that is defined it will be called. In Arduino, it is actually defined in HardwareSerial.cpp. The Apollo3 board library has as part of the never-ending loop in main.cpp only loop().

Now it looks as if it is a serial interrupt, but if you check the code in Arduino it is clear that it only checks whether Serial data is available AND the serialEvent routine exists. If so, it will call that serialEvent-routine.

It is easy to add that in the loop() in your sketch.
By YellowFlower
#225954
Thanks Paul!

I reviewed the hardwareserial.cpp / .h files.

I'm not sure I understand what a weak reference is.
I tried running the serialEventRun() method which doesn't work and tried referencing it as serial.serialEventRun() which doesn't compile.

are you able to show me a very basic example?

any help would be really appreciated.

YF
By paulvha
#225955
it is defined as weak which means "it MIGHT be in place defined somewhere else". Using the information from https://www.arduino.cc/en/Tutorial/Buil ... erialEvent.

This does basically the same as Arduino does...
Code: Select all
/*
  Serial Event example

  When new serial data arrives, this sketch adds it to a String.
  When a newline is received, the loop prints the string and clears it.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent
*/

String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }

  // now check whether anything has been received
  serialEvent();
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]