Strange Problem with Serial1 to COM1 test program

I am having a strange problem that I have been unable to track down after endless hours. I created a small test program to help further investigate but what I am seeing makes no sense. Perhaps someone might suggest other things to try.

I have a simple program that writes a periodic message to Serial1 and to Serial in order to see the same data on a terminal program acting as a Photon console The program also brings in data from Serial1 if anything is available, and displays the input in hex form on the Photon console. Serial1 is going through a Sparkfun level converter and is plugged into COM1 on the test computer. COM! is also being monitored by a terminal program. The baud rate on Serial1 and COM1 is 38400 and no flow control.

I have crossed the TX and RX lines from Serial1 going into the SparkFun. As a result, the periodic message from the Photon appears properly at COM1. And any data I type into COM1 from the terminal program, does appear on the Photon console showing me that Serial1 input is working. So in this configuration everything is working as expected.

Now here is the totally confusing part. I put the TX and RX lines from the level converter back into their proper positions and connect the Sparkfun through a NULL modem connector and into COM1. This never works. I see no output to Serial1 or input to Serial1 when I do this. But the null modem is just swapping TX and RX for me so I don’t need to cross the TX to RX and RX to TX that I was doing when it worked. This is the only difference between the first test case and the second case with the NULL modem in place.

This makes absolutely no sense to me. I have not idea why the case with the NULL modem is not working when the first case essentially was wired as a NULL modem.

I even buzzed out my null modem lines to make sure TX and RX are crossed and that the ground lines are connected to each other through the NULL modem.

This has really kept me going for far too long. I just can’t tell what is blocking the 2nd case from operating. It really is no different than the first case except for where the wires are crossed.

Perhaps someone else reviewing this dilemma might make some suggestions on what I might try.

The SparkFun RS232 level shifter has the output on pin 2 and input on pin 3 of the female DB-9. That makes it a RS-232 DCE device, like a modem. The computer serial port is a RS-232 DTE device. So you should not need a null-modem between the two because the SparkFun device IS a a modem, from the computer’s point of view. I think.

1 Like

Well here is some additional evidence to what is going on. While writing out the description, a thought came to mind to try. As I noted at the end of the report, the only difference between Case 1 and Case 2 is where the TX and RX are crossed. So I decided to leave the TX and RX crossed from the SparkFun level converted and insert TWO Null modems into the path from the SparkFun and COM1. So this would be using the same NULL modems that individually failed to work. This configuration should switch TX and RX then switch them back to the original setting coming out of the Photon.

THIS WORKED. This seems to be indicating that the crossover needs to be done between the Photon and the level converter. The device I am ultimately going to connect to,has the TX and RX lines crossed so one would not normally have used a NULLmodem. But this test seems to indicate I need to cross TX and RX out of the Photon then insert a NULL modem from the SparkFun before it goes into mydevice that has internatl NULL modem wiring.

Why would I have to cross TX and RX out of the Photon all the time to get this to work instead of inserted a NULL modem from the SparkFun level converted that is feeding COM1.

I don’t understand why it matters where the TX and RX lines are crossed.

@rickkas7 - the issue regarding were to switch the TX and RX lines is a function if the device you are connecting to has a null modem in the device itself or does not. To connect the Photon to a PC COM1 port, you must cross TX and RX from the Photon to the SparkFun level converter or it will not work. Everything out of the level converter are straight through wires.

But what you said may be the real answer. That the Sparkfun level convert specifically has an input line and an output line and it is expecting the Photon’s TX to go into the Sparkfun RX and vice versa. That these lines must always be set up this way and that if no cross wiring is required, it must be done after the SparkFun device.

Yes, it matters because the RS232 drivers on the SparkFun adapter are direction-dependent. Pin 2 of the DB-9 is always in input and pin 3 is always an output (from the adapter). You have to swap TX and TX between the level shifter and the Photon.