Software Serial - Corruption

Hi All

I have a small project that is using an Arduino Pro Mini + a Max232 chip.

The Pro Mini is connected via a FTDI usb cable to the PC, we will call this COM4

Now I have a COM1 on the PC and I have an app sending a string of data once per second at 9600,n,8,1

This COM1 from the PC is connected to the Arduino via pin 10 (10=RX)

So I have a Software Serial setup with Pin 10 as RX, 11 as TX

SoftwareSerial SoftwareSerialPort(10, 11); // RX, TX

I need to re transmit the serial data received to the TX of the software Serial port in real time.

The software serial TX is connected to another Serial Port (COM3) on the same PC (for testing purposes)

The problem seems to be this code

void loop() { if (SoftwareSerialPort.available()) { char ch = SoftwareSerialPort.read(); SoftwareSerialPort.print(ch); } }

If I send the CH character out to the hardware serial port there is no corruption at all. But if I send it to the software serial I get corruption of the data that is received.

WHY?

Chris

Hi can you please post your entire code, with code tags please.

Tom..... :)

TomGeorge:
Hi can you please post your entire code, with code tags please.

Tom… :slight_smile:

Hi Tom

Thanks for the reply - but it seems like a Software Serial Issue…

#include <RCSwitch.h>
#include <SoftwareSerial.h>

#define MINIMUM_TIME_IN_MS_FOR_NEXT_BUTTON_CLICK_EVENT 2500
#define SOFTWARE_SERIAL_WEIGHT_MACHINE_SERIAL_TIMEOUTMS 3000
#define BUTTON_CAPTURE_OVERRIDE_WEIGHT_MACHINE_SERIAL_OUTPUT_TIMEOUTMS 2000
#define BUTTON_CLICK_COMMAND "ButtonClick"
#define BUTTON_RECEIVED_COMMAND "ButtonReceived"

RCSwitch RF433MhzSwitch = RCSwitch();
SoftwareSerial SoftwareSerialPort(10, 11); // RX, TX
long lastEvent = 0;
long RF433MHZCommand = 0;

byte Buffer[17];
int BufferOffset = 0;
boolean Initializing = true;
boolean IsCapturing = false;

unsigned long LastRF433MHZButtonClickEventMillis = 0;
unsigned long SerialMillis = 0;
unsigned long LastButtonClickCommandReceived = 0;

void setup()
{
 RF433MhzSwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2

  // Initialize the serial ports - the primary hardware serial and the secondary software serial ports
  Serial.begin(9600);
  SoftwareSerialPort.begin(9600);

  // Initialize variables
  SerialMillis = millis();
  LastButtonClickCommandReceived = 0;
}

void loop()
{
//  CheckForRF433MhzButtonClick();
//  CheckForButtonReceivedEvent();
//  CheckSoftwareSerialForIncomingWeightData();
// CheckCapturingForTimeout();

if (SoftwareSerialPort.available())
{
  char ch = SoftwareSerialPort.read();
//  SoftwareSerialPort.print(ch);
  Serial.print(ch);
}
}

I have removed a lot of commented out code, so the code is pretty straight forward,

The thing is can a software serial receive/send at the same time?

The only thought I have had is to create 2 software serial ports and receive on 1 and send on the other?

So the code is AS IS - how it is working right now.

If I comment out Serial.Print and allow it to be SoftwareSerialPort.print I get corruption.

Chris

The serial connections as described in your initial post are not clear to me.

Skipping to your latest post …

You have 2 serial connections - hardware Serial and SoftwareSerialPort

What is each of then connected to?
What sends data to SoftwareSerialPort?
If you bring the line SoftwareSerialPort.print(ch); into use, where do you expect the output to appear?

I suspect the problem may simply be that software serial cannot transmit and receive at the same time

…R

Robin2: The serial connections as described in your initial post are not clear to me.

Skipping to your latest post ....

You have 2 serial connections - hardware Serial and SoftwareSerialPort

What is each of then connected to? What sends data to SoftwareSerialPort? If you bring the line SoftwareSerialPort.print(ch); into use, where do you expect the output to appear?

I suspect the problem may simply be that software serial cannot transmit and receive at the same time /quote]

Hi

you may be right , or it could be I am using a 433Mhz library that uses Interupt 0 as well.

I am just trying to read info about it now.

Basically I have this

1) A device that is powered by a FTDI USB cable, and this is SAY COM3 2) The arduino recieves data from a serial device via DB9 3 The arduino rebroadcasts the same data to another DB9 connection

Technically I am just inserting the Arduino into the current serial data stream.

In my case it is a digital weight station with an external display board.

I need to grab the data on the way to the external board, and some times forge some data. This not relevant to the issue at hand...

So basically I am inserting the arduino into the serial data and rebroadcasting the same data.

Looking at the softeware serrial linrary at http://arduino.cc/en/Reference/softwareSerial

Limitations

The library has the following known limitations: If using multiple software serial ports, only one can receive data at a time.

I wonder if this is what I am seeing.

chris

I found a reference to a 3rd party library
http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

It mentions:

NewSoftSerial (SoftwareSerial in Arduino 1.0 & later) - Can have multiple instances on almost any pins, but only 1 can be active at a time. Can not simultaneously transmit and receive. Can interfere with other libraries or HardwareSerial if used at slower baud rates. Can be sensitive to interrupt usage by other libraries.

well that is my problem right there.

I will try the different library

Cheers

Chris

Basically I have this

1) A device that is powered by a FTDI USB cable, and this is SAY COM3 2) The arduino recieves data from a serial device via DB9 3 The arduino rebroadcasts the same data to another DB9 connection

Technically I am just inserting the Arduino into the current serial data stream.

This does not answer my questions in a meaningful way.

In the code you posted earlier there are only 2 connections (if I understand things), Serial and SoftwareSerialPort but now you mention 3 connections. And since you correctly referred earlier to Serial being hardwareSerial it seems like there may be 4 connections - Hardware serial, the FTDI cable and 2 separate DB9 connections. Perhaps you can see why I am confused.

Please explain what devices are connected to what Arduino connections when you run the test code in your Reply #2.

Also please explain what the two DB9 connections belong to.

...R