Issues with Software serial

Hi. I have problem with the garbage in my software serial data,

If I connect software serial to usb native everything is Ok, data flow going well. but if I use only software serial to communicate with the board, only first byte is OK and then garbage.

Im using ZERO + TTLUSB

Have written simple echo test, that have same issues:

#include <SoftwareSerial.h>

int main()
{
  init();
  SoftwareSerial softSerial(8,9);
  softSerial.begin(9600);
  
  while(!softSerial) {;;}
  
  while(true)
  {
    if (softSerial.available())
    {
      softSerial.write( softSerial.read() );
    }
  }
}

any idea why data flow is corrupted?

btw same story on all speeds, even 300, if sending bytes with the interval everything ok, but if send 2 or more bytes at once = problem

Are you using 3.3V everywhere?

Maybe it is because you bypassed the normal Arduino initialization by defining your own main(). Try writing it as an Arduino sketch:

#include <SoftwareSerial.h>
  SoftwareSerial softSerial(8,9);

void setup() {
  softSerial.begin(9600);
  }
  
void loop() {
    if (softSerial.available()) {
              // Echo softSerial to itself
      softSerial.write( softSerial.read() );
    }
}

johnwasser:
Maybe it is because you bypassed the normal Arduino initialization by defining your own main().

same story with your sketch

J-M-L:
Are you using 3.3V everywhere?

Yep ZERO is 3.3v only, usbttl supports both

Where are Rx and Tx connected to?

J-M-L:
Where are Rx and Tx connected to?

8pin - usbttl TX
9pin - usbttl RX

ohh. figured out.. I am stupid, writing in to the serial port while retrieving data caused the issues. need just buffer all incoming data flow and then use write function.