Teensy to PC rs232 communication with Differential Bus Tranceiver

Hi there,

I'm trying to get a project going that involves sending and receiving data from a computer to a Teensy 3.0 via a rs485 cable. I'm currently transmitting successfully from the Teensy to the computer and viewing the data from the COM port however when I try to send data to the Teensy and repeat it back I have no luck. I'm not sure if I'm using the correct enabling for sending/receiving or not. Any help would be greatly appreciated. Attached is a rough diagram of how I have the device wired up.

Here is my code:

#include <SoftwareSerial.h>

byte byteRead;
const int writeEnable=23;
void setup()
{
Serial1.begin(9600);
pinMode(writeEnable,OUTPUT);
digitalWrite(writeEnable,HIGH);
}

void loop()
{
digitalWrite(writeEnable, LOW);
delay(25);

if(Serial1.available() > 0)
{
byteRead=Serial1.read();
}

Serial1.println (byteRead);
digitalWrite(writeEnable, HIGH);

delay(50);
}

Hi rekcut,

An RS232 port is a single ended topology with a +-12V signal on its Rx/Tx pins. The RS485 driver is a differential 0-5V signal accross the A and B pins. Your connection schematic will never work and you are probably lucky that you did not pop the drivers ic as the A and B lines can take a 12V common line voltage without destroying itself.

You need another RS485 driver ic accepting the 0-5V differential output signal from A and B (from the first driver ic )and converting it back to single ended half duplex 0-5V signal on the R and D pins. You would then connect the R and D pins to a level translator ic like a MAX232A (or similar) that connects to the COM port. The RS232 COM port is a single ended +-12V topology. The level translator ic converts the 0-5V single ended signals to a +-10V signal for the PC com port.

Have a look at Google Code Archive - Long-term storage for Google Code Project Hosting. this site contains a modbus library with schematics. There is quite allot of info there. Also have a look at the forum thread Help with ModBus RTU Master-Slave: SimpleModbus [SOLVED] - Networking, Protocols, and Devices - Arduino Forum