SoftwareSerial reading wrong values

Hi there,

I'm trying to use the software serial library in my arduino Uno to read packets from a TI CC1350. I set a constant packet {37,97,42,66} to test the comms and see if it is working, but it shows a very erratic behavior. Every time a packet is read, the values are different. My arduino code only reads the software serial port and prints it back to the monitor. Code:

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 10

SoftwareSerial mySerial(rxPin,txPin); //(rx,tx)

void setup() {
  
  pinMode(txPin,OUTPUT);
  pinMode(rxPin, INPUT);
  Serial.begin(9600);
  while(!Serial);
  mySerial.begin(9600);
  Serial.print("Ready to receive data");
  Serial.println();

}

void loop() {
  byte frame[4] = {0,0,0,0};
  mySerial.listen();
  if(mySerial.available()>= 4){
    frame[0] = mySerial.read();
    Serial.print(frame[0]);
    Serial.print(" ");
    frame[1] = mySerial.read();
    Serial.print(frame[1]);
    Serial.print(" ");
    frame[2] = mySerial.read();
    Serial.print(frame[2]);
    Serial.print(" ");
    frame[3] = mySerial.read();
    Serial.print(frame[3]);
    Serial.print(" ");
    Serial.println();
  }
  frame[0] = 0;
  frame[1] = 0;
  frame[2] = 0;
  frame[3] = 0;
}

One exemple output:

Ready to receive data
183 117 47 82 
154 225 62 90

The hardware serial is already being used, so I really nee to use software serial. I've tried changing the baud rate, puting resistors on the line, using altSoftSerial and NeoSWSerial, but to no avail. i've also used an osciloscope in the TX output to check if the CC1350 was sending bad data, but it isn't. The TX is fine, problem is with RX. The board sending the data is operating in 3V3 and the the arduino with 5V, could this be the problem?

Thanks in advance!

Can you send alphabetic characters for testing? It will make debugging easier.

Have you a GND connection to the sending device?

Is the sending device using TTL voltages or RS232 voltages which are not compatible with an Arduino?

Post a link to the datasheet for the sending device?

...R
Serial Input Basics - simple reliable ways to receive data.

Robin2:
Can you send alphabetic characters for testing? It will make debugging easier.

Yes, I can. I have now sent a buffer with all uppercase letters {65,...90} and the result was this:

Ready to receive data
113 195 255 127 255 255 111 234 75 234 223 255 255 239 127 216 213 242 255 223 255 255 95 126 123 122 255 
69 123 127 247 127 187 255 222 95 123 127 255 255 127 95 83 245 246 251 254 223 118 223 248 221 255 255

Robin2:
Have you a GND connection to the sending device?

No, grounds are not connected.

Robin2:
Is the sending device using TTL voltages or RS232 voltages which are not compatible with an Arduino?

sending device is using 3V3 TTL voltage, not RS232.

Robin2:
Post a link to the datasheet for the sending device?

Sure: http://www.ti.com/lit/ds/symlink/cc1350.pdf

pedro2168:
No, grounds are not connected.

They should be.

And if the Arduino's 5v Tx is connected to the 3.3v Rx you will have a problem. You will need to use a voltage divider to drop the Tx's 5v to 3.3v.

The Arduino's Rx should be able to read the 3.3v signal.

...R

OK, I'll try connecting the grounds.

Tx has a voltage divider, even though I do not use it. I only receive data, never send anything.

Thx for the info, will get the feedback here as soon as I can test the setup.

pedro2168:
Tx has a voltage divider, even though I do not use it. I only receive data, never send anything.

The Tx pin will always be HIGH when it is idle.

...R

Thx a lot Robin!

It worked fine.

Thx for the support!