How to Define 3rd serial port on STM32F411CE BP

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

How to Define 3rd serial port on STM32F411CE BP

Post by imk »

Hello,
I am trying to define a third serial port on a STM32F411CE Black Pill and the program never sends on third port and crashes after a second or two.
Hello as can be seen in the code below I am enabling three serial ports and have tried Serial3 & Serial6 for the 3rd port but can't get it to work.
Serial, Serial1 and Serial2 work as expected but I am obviously missing a bit of magic to get the 3rd port working.
Also if the program calls Serial3.println("000"); or Serial6.println("000"); the program will crash after a few seconds and no longer send on Serial1 and Serial2. Any ideas please?

Many thanks in advance imk



#define LED_PIN PC13 // Black Pill

HardwareSerial Serial2( PA3 , PA2 ); // Rx Tx

HardwareSerial Serial3( PB0 , PB1 ); // Rx Tx
//HardwareSerial Serial6( PB0 , PB1 ); // Rx Tx

void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);

Serial3.begin(9600);
//Serial6.begin(9600);

pinMode(LED_PIN, OUTPUT);
}

void loop()
{
Serial1.println("123"); // Goes to Pin PA9
Serial2.println("ABC"); // Goes to Pin PA2

//Serial3.println("000"); // Goes to Pin
//Serial6.println("000"); // Goes to Pin

digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);
}
1201 Alarm
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: How to Define 3rd serial port on STM32F411CE BP

Post by GonzoG »

First, USART6 (3rd serial) is on PA11, PA12, you cannot reassign hardware interface to any pins you want..
Second the same pins are used for USB, so you cannot use USART6 when USB is enabled.
imk
Posts: 31
Joined: Fri Sep 24, 2021 9:26 pm

Re: How to Define 3rd serial port on STM32F411CE BP

Post by imk »

GonzoG
Thanks for heads up.
But i thought hardware serial pins had defaults but could be redefined, must be me thanks again.
imk
1201 Alarm
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: How to Define 3rd serial port on STM32F411CE BP

Post by GonzoG »

They can but only to pins that have that functionallity.
imk
Posts: 31
Joined: Fri Sep 24, 2021 9:26 pm

Re: How to Define 3rd serial port on STM32F411CE BP

Post by imk »

GonzoG
Many thanks for clearing that up, now it makes sense.
BTW I recoded the test app for searial6 to pins PA11 and PA12, unplugged the usb power and powered board from external 5v and have serial6 working.
This is a goodly move forward as can now drive the other serial device I was thinking of adding to the main project.
Many thanks imk
1201 Alarm
Post Reply

Return to “General discussion”