STM32 multi software serial

  • Post author:
  • Post category:STM32

https://github.com/liyanboy74/soft-uart

soft-uart-master

Multi Software Serial (UART) For STM32

The library work fine for virtualize 6 UART full duplex in baud rate 9600. All UART work together parallelly!

Library Dir:

Handler & baud rate

The function  SoftUartHandler(void) must call in interrupt every  0.2*(1/BR) .

if  BR=9600 then  0.2*(1/9600)=20.8333333 uS

highly recommended set maximum CPU clock for Run Handler faster as possible! you also available for use lite version by limited options for slow MCUs.

The library don’t change any GPIO config! before using must config TX pins as output and RX pins as input , any TX pin must set to 1 as IDLE and any RX pin must be Pullup.

Example Timer Config

for Baud Rate 9600 :

Config value
Timer Clock 72 MHz
Prescaler (PSC – 16 bits value) 74
Counter Period (AutoReload Register – 16 bits value ) 19
auto-reload preload Enable
Tim global interrupt Enable

You also can use Timer frequency calculator.

Calling handler

 

Config Soft UART

Open  softuart.h and edit bellow line as you want:

If  Number_Of_SoftUarts=6 that mean you  SoftUartNumber is  0,1,2,3,4,5

After config timer for config Soft UART use  SoftUartInit:

Using Soft UART

Transmit always is Possible but for Receiving data you must enable listening by calling:

Received data stored in buffer accessible by below functions:

Transmit data:

Example test:

Transmit

Receive

Example 1:

Example 2:

Full Example 3: