Serial baudrate 1200

All about boards manufactured by ST
Post Reply
dani68k
Posts: 3
Joined: Fri May 26, 2023 1:21 pm

Serial baudrate 1200

Post by dani68k »

Hello,

I'm trying to set a Serial communication with baudrate of1200, 7 databits, parity even.
Actually, it is for a SD-12 communication.
Anyone knows how set a Serial with a baudrate of 1200?
I tryed to use SoftwareSerial to get baudrate 1200 but then the issue is with databits and parity.
Serial.begin just works with baudrate 2400, below that the MCU seems to be freezed...
I will have 2 Serial more: 1 for log/debug 115200 and 1 for a NEXTION 115200.

I'm using a NUCLEO-L476RG with PlatformIO.

Thank you.
BR,
dani68k
dani68k
Posts: 3
Joined: Fri May 26, 2023 1:21 pm

Re: Serial baudrate 1200

Post by dani68k »

Hello,

I've been digging a little bit... I found to get 1200 baudrate I should down the clock frequency.
Now, I'm trying how to proceed with it.
Another point is to use SoftwareSerial and manage 7bits Parity even manually.

I hope I can share with you my results.
Any help or comments will be great.

Thank you.
Best regards,
dani68k
dani68k
Posts: 3
Joined: Fri May 26, 2023 1:21 pm

Re: Serial baudrate 1200

Post by dani68k »

Hello,

So, I changed this line 134 in variant_NUCLEO_L476RG.cpp to:
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; --> RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;

Now clock is changed 80Mhz to 40Mhz, enough to get a baudrate of 1200.
Final serial configuration --> Serial.begin(1200, SERIAL_7E1);

I wrote a liitle program to test:

#include <Arduino.h>

uint32_t count;

void setup() {
Serial.begin(1200, SERIAL_7E1);
Serial.println(F_CPU);//Check system clk in hz
}

void loop() {
count++;
Serial.println("Value of count is: " + String(count));
delay(1000);
}

In realterm terminal I can see data with config of 1200bauds 7bits Even parity 1 bit stop.
Captura de pantalla 2023-05-29 130206.png
Captura de pantalla 2023-05-29 130206.png (36.69 KiB) Viewed 6341 times
It seems everything is working as I want.

Thank you.
Best regards,
dani68k
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”