Page 2 of 2

Re: Serial1Event Not working

Posted: Tue Feb 08, 2022 12:39 pm
by imk
hello fpistm

read wiki, tried:
HardwareSerial Serial1(PA10, PA9);
build_opt.h -DENABLE_HWSERIAL1
and various compile options and just getting mega compile errors.

So have given up trying to get STM serialevent to work, hence will just use serial.available().
Not solution i wanted but serialevent in STM is just to painful.
Many thanks for all you help.
imk

Re: Serial1Event Not working

Posted: Tue Feb 08, 2022 3:35 pm
by fpiSTM
Well, in fact by default the STM32 core define default pins and U(S)ART peripheral.
For the Blackpill F411CE it is PA10/PA9 which are linked to USART1peripheral:
https://github.com/stm32duino/Arduino_C ... #L131-L143

This means it will instantiate by default Serial1 instance and map it to Serial.
So by default the serialEvent() is enabled.

If you use the default SerialEvent example available in the "04. Communication" submenu of the Arduino examples you will see it works properly.
Note that serialEvent is not linked to an interrupt, it is call after each loop and check if a byte is available for each Serial initialized at compile time ( for each ENABLE_HWSERIALx defined).

I think your example does not work because you call it serial1Event instead of serialEvent1 or serialEvent (generic name for default Serial instance).

For ref: https://www.arduino.cc/reference/en/lan ... rialevent/

Anyway your sketch will always print "REPLY" after the first byte send as it is never read.