Interfacing Mega1280 with Serial sensor

Hello everyone. I have been a regular visitor to your wonderful online community for about 6 months now and have spent many hours reading.
I purchased a Mega and currently working on interfacing it with a Telaire 8001 CO2 sensor through its built in RS-232 port. The sensor communicates with a proprietary protocol.

I will continue in next post so I can include links.

Please stay tuned...

Details:
The sensor is a Telaire 8001 Single-Beam Infrared CO2 Gas Dispersion Sensor > telaire.com
It has an RJ45 type jack which, when used with a RJ45-DB9 adapter, can be used to connect the unit through a PC serial port. They provide a utility to change settings, test, and calibrate the sensor.
I have successfully connected to the sensor with their software on an XP virtual machine (since the utility apparently doesn't like Win7x64).

The problem I am having is when I try to talk to it with my ATMega1280.
Here's what I know about the sensor:

I have an ATMega1280 running off of USB power and I'm running Arduino-0018 IDE. On a breadboard I have a MAX235 Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf. As seen on Figure 13 of the MAX235's datasheet, I have pins 8 and 9 on the MAX235 going to Pins 18 and 19 on the Mega, respectively. I have pins 11 and 12 on the MAX235 going to ground and +5v on Mega, respectively. I have Pins 20 and 21 on the MAX235 tied LOW. I have Pins 3 and 10 on the Max235 going to the Tx and Rx pins on the sensor's Rj45 jack (Pins 1 and 2), respectively. The sensor's ground pin on its RJ45 jack (Pin 3), the MAX235's ground pin (Pin 11), and the Mega all share a common ground.

I have set up a simple test sketch to try to initiate a conversation between the sensor and the Mega. If I send any character on Serial0, it sends out a STATUS command to the sensor on Serial1. If the Mega receives a response from the sensor, it is echoed back on Serial0.

Code is a bit of a mess because I'm been trying so many different things to get this to work.

//uint8_t Req_Co2[5] = {255, 254, 02, 02, 03}; 
const byte FLAG = 0xFF;
const byte BRDCST = 0xFE;
const byte CMD_READ = 0x02;
const byte CMD_UPDATE = 0x03;
const byte CMD_STATUS = 0xB6;
const byte hex_one = 0x01;
const byte hex_two = 0x02;

const byte CO2_PPM = 0x03;
const byte ELEVATION = 0x0F;

void setup() {
  Serial.begin(9600);
  Serial1.begin(19200);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  
  digitalWrite(3, HIGH);
  delay(50);
  digitalWrite(3, LOW);

}

void loop() {
  // read from port 0, send commands to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    
    //Serial1.write(Req_Co2, 5);
   
    //Serial1.print(FLAG);
    //Serial1.print(BRDCST);
    // Serial1.print(hex_one);
    //Serial1.print(CMD_STATUS);
    //Serial1.print(CO2_PPM);
   
    Serial1.print(FLAG, BYTE);
    Serial1.print(BRDCST, BYTE);
    Serial1.print(0x00, BYTE);
    Serial1.print(0x01, BYTE);
    Serial1.print(CMD_STATUS, BYTE);
    
    //Serial1.print(CO2_PPM, HEX);
    
    digitalWrite(2, HIGH);
    delay(500);
    digitalWrite(2, LOW);
  }

  // read from port 1, send to port 0:
  if (Serial1.available()) {
    byte inByte = Serial1.read();
    Serial.print(inByte, HEX); 

    digitalWrite(3, HIGH);
    delay(500);
    digitalWrite(3, LOW);
  }
}

I have tested loopback by shorting Pins 3 and 10 on the MAX235. I correctly read back the command I send out to the sensor on the Serial Monitor. I have tried reversing Tx and Rx Pins on the sensor to no avail.
As I mentioned earlier, I tested the sensor's Serial communication with my PC, so I know things on that end are working correctly. I don't have an oscilloscope, but I can measure -9.25v coming out of the RS232 Tx Pin (Pin 3) on the MAX235, and -9.84v on the Tx Pin on the sensor's RS232/RJ45 port.

I have spent many hours reading trying to find a solution, but I have come to a point where I'm not sure what to try next. I turn to the many brilliant minds that roam this forum to help in my journey....

Hey everyone. Been at this for several more hours with no progress...

Any suggestions at all? I've spent about 3 weeks trying to work through this with no luck. I'm hoping than more experienced duino users notice something I am overlooking....

Please help!!!

I don't have an oscilloscope, but I can measure -9.25v coming out of the RS232 Tx Pin (Pin 3) on the MAX235, and -9.84v on the Tx Pin on the sensor's RS232/RJ45 port.

You are aware that these are not valid voltages to feed to an Arduino, right?

These need to go through a Serial to TTL inverter to get voltages that the Arduino can handle.

Yes Paul, that is the purpose of the MAX235. It is a MAX232 variant with internal capacitors.

The voltages I listed were voltages on the RS232 side of the MAX235 and what was coming out of the sensor (also RS232). So the voltages are expected to be +-12v.

Thank you, though, for the response.

I have no idea where I'm going wrong. The Mega spits out the commands through the MAX235 correctly...

Anyone else have experience interfacing an Arduino with other non-Arduino microprocessors (since that's essentially whats going on here)? Any special considerations I need to be taking i.e. serial timing issues?

I find it odd that I can successfully talk to sensor through my PC serial port, but not the Mega's Serial1?!?!?

STUMPED!

does it use just the rx and tx lines, no control lines?

The sensor uses Pins 1,2,3 on the RJ-45 connector: Rx,Tx,Gnd. I have those going to their respective pair on the MAX235.

No control lines.

Yes, it would be useful if the sensor manufacture would give you the pin out of their RJ45 connector to determine which wires are used. It could very well be that it needs a true DTR signal (+12vdc) applied before it will 'listen' to the data line. Most PC serial drivers do turn on the DTR signal by default when they open the serial port.

Lefty

They do provide pinouts. All information I have shared has been gathered through their technical documents and such.

The sensor only communicates with 3-pin serial link: only Tx,Rx, Gnd. They provide an RJ-45 to DB9 adaptor. I took it apart and it only uses pins 1,2,3, going to Rs232 Tx,Rx,Gnd.

As a matter of fact, I hooked it up to my pc by splicing a serial cable to an ethernet cable, using only the 3-wires reffered to above.

Let's see, do you guys recommend a particular serial port sniffer? If I can see what the utility program on the PC is saying to the sensor, maybe it can shed some light on what's going on...

I have swapped wires for hours... I know which wire is which as I spliced into an existing serial cable and have identified each as such (on the sensor end, that is).
Also, if I wire the MAX235 incorrectly (i.e. if pins 18 and 19 on the Mega are reversed), I don't correctly get a loopback through the 235. So I know I have that correct as well...

Thank you all for your help so far.

No sir, no scope available. I would like to see if I can capture chatter between the pc and sensor... What would be the best way to accomplish this? Do I need an In-the-Middle setup, or can I do it purely through software?