Is the serialEvent() works with Arduino R4 ?
With my Arduino R4 it's not ok
My code (from Arduino Site....)
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 == '\r')
{
stringComplete = true;
}
}
}
I have not tried this out yet, but I suspect that it is currently not implemented.
That is if you look at the current code in main.cpp
The code loop looks like:
setup();
while (1)
{
loop();
}
Whereas for example if you look at their AVR code
It looks like:
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
And it is the serialEventRun() code that checks for the different Serial ports, and does the check to see if they have any pending data and if so, call the appropriate serialEvent call.
Even in Arduino's first boards platform "Arduino AVR Boards", the serialEvent system doesn't work for all the boards. And the same goes for the "Arduino SAM Boards (32-bits ARM Cortex-M3)" and "Arduino SAM Boards (32-bits ARM Cortex-M3)" platforms.
There are some indications that there is no intent to perpetuate the system:
adding a full SerialEvent (as in AVR) is not going to happen (we should obsolete it asap).
So I wouldn't hold your breath for the implementation of this. The system doesn't offer anything of significant value and also makes the sketch program flow more difficult to understand because the user might get the impression that the callback will be called asynchronously (which was the original interrupt-based design of the system many years ago). In reality, blocking code in the loop blocks the callback, which would be clear if the user simply called the function from the loop.
So you can just add a few lines to your loop function instead:
Thanks @ptillisch good information on where Arduino is going with this.
While I never liked how these were defined, I am Sort of surprised. It probably would not be hard to implement for the UNOR4 for just Serial and Serial1. But...
Side notes: On Teensy boards, it is/was slightly more useful as the calls to do things like SerialEvent1 were put into a function called yield(), which was called in the loop calling loop(). But in addition to there it was called in other places, like within delay()...