Serial data seeing random characters

Ash

Member
Hi all, after facing some problems with my serial data transfer between two teensy modules last year, I have decided to restart from scratch with sample programs. I have two Teensy modules - Teensy1 and Teensy2.

Teensy1 is for sending data on Serial 6 and the sketch is as follows:
C++:
char tx_arr[22];

#define Teensy2 Serial6

uint8_t count;
static uint32_t CurrTime, PrevTime;

void setup()
{

  Teensy2.begin(115200);
  Serial.begin (9600);
}

void loop()
{
  CurrTime = millis();
  if((CurrTime-PrevTime) > 1000)
  {
    Serial.print("TX Prog  --->");
    Serial.println(count);
    sprintf(tx_arr,"Hi my name Teensy1 %u",count);
    Serial.println(tx_arr);
    PrevTime = CurrTime;
    Teensy2.print(tx_arr);
    Teensy2.print('\r');
    memset(tx_arr, '\0', sizeof tx_arr);
    count++;
  }

}

Teensy2 is for receiving data on Serial 5 and the sketch is as follows:
C++:
#define Teensy1 Serial5

char rx_arr[90];
static uint8_t ndex;

void setup()
{
  Teensy1.begin(115200);
  Serial.begin(115200);
}

void loop()
{
 
  while(Teensy1.available())
  {
    char datachar = Teensy1.read();
    rx_arr[ndex] = datachar;
    //Serial.print(datachar);
    if(datachar=='\r')
      {
        rx_arr[ndex]='\0';
        Serial.println(rx_arr);
        ndex=0;
        memset(rx_arr, '\0', sizeof rx_arr);
        break;
      }
      
    ndex = ndex + 1;
  }
}

On checking the serial data received at Teensy2 on the Serial Monitor, I am seeing some random characters every now and then. How can I stop this from happening?
SerialProb.JPG


Thanks in advance!
 
Back
Top