How to define Serial3 to other pins?

Post here first, or if you can't find a relevant section!
nawasaqi
Posts: 20
Joined: Wed Dec 22, 2021 7:06 pm

How to define Serial3 to other pins?

Post by nawasaqi »

Hi, I have this mma stm32f411 question and I would like to read the i2c data on pins PA11 and PA12 (Pinout https://miro.medium.com/max/3122/1*ixFS ... 0w6jFA.png)

Code: Select all

HardwareSerial Serial3 (PA11, PB12); 
Serial3.begin(9600);
IBusServo.begin(Serial3);

But something does not read me and I do not know why when I use standard serial1 PA9, PA10

Code: Select all

  IBusServo.begin(Serial1);
everything works ok. But I would like to use other pins because I have other tx and rx pins from serial to serial2 busy.


Thank you for your help
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: How to define Serial3 to other pins?

Post by ag123 »

pa11, pa12 is normally usb, make sure not to select usb - serial if you want to use it.
it also isn't an i2c port
nawasaqi
Posts: 20
Joined: Wed Dec 22, 2021 7:06 pm

Re: How to define Serial3 to other pins?

Post by nawasaqi »

It's actually not i2c. I'm sorry but I'm just learning. I will start differently, how to assign any two pins to RX and TX? I found the software serial library but I don't know how to make RX and TX from any two pins.
For example, PA0 and PA1.

if I do it, unfortunately I don't get any data on telemetry.

Code: Select all

#include <./IBusBM.h>
#include <SoftwareSerial.h>

IBusBM IBusServo;
static const int RXPin = PA0, TXPin = PA1;
SoftwareSerial ss(RXPin, TXPin);
  
void setup() {
  Serial.begin(115200);
  
  ss.begin(9600);

  IBusServo.addSensor(IBUS_MEAS_TYPE_S85);

}

void loop() {
  ibusServo();
  
}

void ibusServo()
{

  IBusServo.setSensorMeasurement(1,23);
  delay(2000);
}
The problem is probably that I have to do

Code: Select all

   IBus.begin (Serial);
Just how to connect it to softwareserial?

I tried so but it doesn't work :(

Code: Select all

   IBus.begin (ss());
Thank you in advance for your help
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: How to define Serial3 to other pins?

Post by ag123 »

for 'beginners' it's better to use default uart1 (PA9 TX, PA10 RX).
Normally, there is an option to select it and it should be pre defined as either Serial or Serial1

try entering a statement like Serial1.println(); and build, if there is no errors, chances are that it is predefined.
otherwise, and in fact you should nevertheless visit
https://github.com/stm32duino/wiki/wiki ... wareserial
that is the api docs for HardwareSerial.

As this is predefined, it should mostly 'just works'
nawasaqi
Posts: 20
Joined: Wed Dec 22, 2021 7:06 pm

Re: How to define Serial3 to other pins?

Post by nawasaqi »

the problem is that on uart1 I have gps on uart2 I have an ibus sensor. And I need one more uart for ibus Servo.
serial 3 is still defined but I don't know what pins I can connect to it. I do not use USB only to upload the software, so I was thinking about pins PA11 and

maybe someone knows the answer, how much uart connector has stm32f411 ?? found markings for bluepill stm32f103

Code: Select all

HardwareSerial Serial1(PA10, PA9); 
HardwareSerial Serial2(PA3, PA2);
HardwareSerial Serial3(PB11, PB10);
is there more series defined serial4, serial5, serial6 .... for stm32f411 ???
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: How to define Serial3 to other pins?

Post by GonzoG »

nawasaqi wrote: Sat Jan 22, 2022 5:03 pm

Code: Select all

HardwareSerial Serial1(PA10, PA9); 
HardwareSerial Serial2(PA3, PA2);
HardwareSerial Serial3(PB11, PB10);
is there more series defined serial4, serial5, serial6 .... for stm32f411 ???
All information about all interfaces and pins you'll find here:
https://www.st.com/resource/en/datashee ... f411re.pdf
nawasaqi
Posts: 20
Joined: Wed Dec 22, 2021 7:06 pm

Re: How to define Serial3 to other pins?

Post by nawasaqi »

I founded that

Uart1 PA9, PA10 busy for me Gps
Uart2 PA2, PA3 busy for me ibusSensor
Uart6 PA11,PA12 busy usb?


so I am asking if I can use serialmonitor to indicate other pins for ibusServo? possibly if I can use PA11 & PA12
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: How to define Serial3 to other pins?

Post by GonzoG »

You can use PA11 and PA12 for USART6 if those pins aren't wired for USB.
STM32 MCUs do not have PIO (programmable IO). You can only change pins if there are alternative pins assigned to interface.
All pins and their available functions are in "Pinouts and pin description" sections of datasheet.
nawasaqi
Posts: 20
Joined: Wed Dec 22, 2021 7:06 pm

Re: How to define Serial3 to other pins?

Post by nawasaqi »

Something is not working for me. When I substitute PA3, PA2, communication works.

Code: Select all

HardwareSerial Serial6 (PA12, PA11); //RX, TX  --> PA3, PA2 Work
  
void setup() {
  Serial.begin(115200);


  IBusServo.begin(Serial6);

Therefore, it probably does not work as it should, because these pins are connected to the USB as you wrote. From what I found, I would have to disable SerialUSB.

Code: Select all

Serial.end();
Is that enough??

And the second question, will I be able to upload the firmware using st-link ??

Thank you in advance for your help
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: How to define Serial3 to other pins?

Post by GonzoG »

nawasaqi wrote: Sun Jan 23, 2022 9:34 am Something is not working for me. When I substitute PA3, PA2, communication works.

Code: Select all

HardwareSerial Serial6 (PA12, PA11); //RX, TX  --> PA3, PA2 Work
The name here is your name. Only pins define which USART interface will be used.

nawasaqi wrote: Sun Jan 23, 2022 9:34 am Therefore, it probably does not work as it should, because these pins are connected to the USB as you wrote. From what I found, I would have to disable SerialUSB.

Code: Select all

Serial.end();
Is that enough??

And the second question, will I be able to upload the firmware using st-link ??

Thank you in advance for your help
You'll have to remove Serial USB completely from program (disable it in board settings in IDE).But I don't think that it will be enough as those pins are wired for USB.
ST-Link is completely different interface. It always works.
Post Reply

Return to “General discussion”