Can't read from serial device?

Status
Not open for further replies.

humjaba

Active member
Hello there

I feel like this is something simple but I can't figure it out. My hardware setup is a teensy 3.1 hooked via Serial1 to a max3232, which is in turn hooked to either my usb->serial interface or my Innovate LC2 wideband controller. Here is the sketch:
Code:
#define HWSERIAL Serial1


void setup() {
	Serial.begin(9600);
	HWSERIAL.begin(19200, SERIAL_8N1);
}

void loop() {
        int incomingByte;
        
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
		Serial.print("USB received: ");
		Serial.println(incomingByte, DEC);
                //HWSERIAL.print("USB received:");
                //HWSERIAL.println(incomingByte, DEC);
	}
	if (HWSERIAL.available() > 0) {
		incomingByte = HWSERIAL.read();
		Serial.print("UART received: ");
		Serial.println(incomingByte, DEC);
                //HWSERIAL.print("UART received:");
                //HWSERIAL.println(incomingByte, DEC);
	}
}

I am trying to read data from my Innovate wideband O2 controller. It spits out data on a serial (rs232) port at 19200kbps, 8N1. I can read this data on my laptop using a serial to usb converter and realterm. I can also connect my serial to usb adapter to my max3232 and send messages from realterm to the teensy (and vice versa) and they show up in the serial monitor. However, when I hook the max3232 up to my wideband controller (through a male-male serial interface), I get nothing. Anyone have any ideas?

Thanks,
Tyler
 
Last edited:
Check out : >> examples\04.Communication\MultiSerial

Serial1 is the 'serial' port.

Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}
 
Check out : >> examples\04.Communication\MultiSerial

Serial1 is the 'serial' port.

Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}

Yes... this is what the code I showed does..
I have HWSERIAL defined as Serial1, which I am communicating with to the max3232.
Serial the serial monitor on my computer, onto which I am trying to relay messages from HWSERIAL/Serial1
 
yep , I missed the first #define line . . . the lines Rx/Tx might be swapped? The Teensy is a 3v device - so with something like this (sparkfun.com max3232) set up and working on the other end that should be right. You can confirm the Teensy looping Serial1 to Serial2 - but I know it works when connected right.
 
Yeah, I tried swapping the lines and no dice. What really gets me is that this works:

realterm (set to 19200,8n1) --> usb/rs232 adapter -> max3232 -> teensy --> serial monitor

and this works

serial monitor --> teensy --> max3232 --> usb/rs232 adapter --> realterm (set to 19200, 8n1)

and this works

wideband lc2 --> usb/rs232 adapter -> realterm (set to 19200, 8n1)


but this doesn't:

wideband lc2 --> max3232 --> teensy --> serial monitor
 
Are you using a board like this for the Max3232?
max3232.png

If not can you post a picture of the setup you do have?

From where I'm sitting it sounds like you either have that compatability issue Paul's suggesting. Which I feel is unlikey as RS-232 is a well defined protocol but is of course entirely possible. Or you have your connections between the wideband LC2 and the MAX3232 wrong

The MAX3232 has an output swing of +/-5V which is the absolute minimum of the RS-232 spec. If more than 2.5mA is drawn this will drop out of spec. This should only effect the transmit side however
 
Last edited:
Are you using a board like this for the Max3232?
View attachment 7335

If not can you post a picture of the setup you do have?

From where I'm sitting it sounds like you either have that compatability issue Paul's suggesting. Which I feel is unlikey as RS-232 is a well defined protocol but is of course entirely possible. Or you have your connections between the wideband LC2 and the MAX3232 wrong

The MAX3232 has an output swing of +/-5V which is the absolute minimum of the RS-232 spec. If more than 2.5mA is drawn this will drop out of spec. This should only effect the transmit side however

This is the exact board (very similar to what you've shown)

https://www.amazon.com/gp/aw/d/B00EJ9NAKA/ref=ya_aw_od_pi?ie=UTF8&psc=1

I'm not sure which chip is in my USB to serial convertor, is it possible that the lc2 is at the ttl level and it just uses a d-sub connector? Any way to find out without frying my Teensy if I'm wrong? I have a multimeter but no scope. The lc2 is broadcasting at all times on the rx line so TX problems shouldn't matter..

Currently running off the Teensy 3.3v output, as the max3232 datasheet seemed to indicate that was alright, but I'll give an external 5v power supply a shot.
 
Last edited:
This is the exact board (very similar to what you've shown)

https://www.amazon.com/gp/aw/d/B00EJ9NAKA/ref=ya_aw_od_pi?ie=UTF8&psc=1

I'm not sure which chip is in my USB to serial convertor, is it possible that the lc2 is at the ttl level and it just uses a d-sub connector? Any way to find out without frying my Teensy if I'm wrong? I have a multimeter but no scope. The lc2 is broadcasting at all times on the rx line so TX problems shouldn't matter..

Currently running off the Teensy 3.3v output, as the max3232 datasheet seemed to indicate that was alright, but I'll give an external 5v power supply a shot.

Got it working - turns out the male/male db9 adapter I got was not mapping the pins correctly through the other side. I hooked it up the old-fashioned way and got it working.
Step 2: Get it talking to my ECU over CAN.
 
Got it working - turns out the male/male db9 adapter I got was not mapping the pins correctly through the other side. I hooked it up the old-fashioned way and got it working.
Step 2: Get it talking to my ECU over CAN.

I think I'm running into the same problem? http://electronics.stackexchange.co...kfun-rs232-shifter-smd-ttl-waveform-dc-offset

I took the pin outs from the 2.5mm stereo <> DB9 cable that came with the Innovate gear. i.e. the tip of the stereo plug is Rx, middle ring is Tx (as I see it on my oscilloscope) and then base ring is ground. That middle ring with the good RS232 signal on it shows up as pin 2 in the DB9 connector, so that's how I wired into the level shifter.

I'll have to try it when I get home, but would you suggest swapping pin 2 & 3 to resolve the issue I'm seeing? (large DC offset in shifter TTL output)
 
Status
Not open for further replies.
Back
Top