Serial1Event Not working

Post here first, or if you can't find a relevant section!
imk
Posts: 31
Joined: Fri Sep 24, 2021 9:26 pm

Re: Serial1Event Not working

Post 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
1201 Alarm
User avatar
fpiSTM
Posts: 1758
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Serial1Event Not working

Post 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.
Post Reply

Return to “General discussion”