Connect with us

propblem with RS232 to RS485 Pleased help!

Discussion in 'General Electronics Discussion' started by anhnha, Apr 26, 2012.

  1. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Hi all,
    I had do the circuit like that.But I wire up in breadboard it is not work.In my project I need to communicate between computer(COMM PORT) and micro.But now I want to check 2 circuits that I had wire in breadboard:
    -the first breadboard for RS232 to RS485
    -the second breadboard for RS485 to RS232
    in reality, I need 2 computers to communicate but now have only one therefore I used TX pin of comm port to transmit and also used RX of this port to receive data.
    Because I only used on computer thus I had connect TX of comm port to 232 input of one breadboard and RX of comm port to 232 output of the other breardboard.And then I used the program i posted above to transmit and receive data from comm port.But when I am not use 5 Voltage connected to ICs and I supprised due to is read from comm port is exact but when power is connected then it is not work.At first I think that it receiced data may be TX and RX is connected to each other but when i used ohm meter to measure the resistance between TX and RX, i received the value is very large and this mean it is not connected.I am confused why it is not connected but i can received data and when power is connnected it is not work.
    I have checked all connected in breadboard, all of them are good.Would you give me how to solved it,i have wire up the circuit in breadboard many times but all are the same.Finally I can not to transmit between two computer.Will i need add something in this circuit in reality?Are there anything wrong in my schematic?
    would you help me check it.I have attach my file in this.
    And this is orginal circuit i had used:http://www.bb-elec.com/bb-elec/literature/485ptbr-3903ds.pdf
     

    Attached Files:

    Last edited: Apr 26, 2012
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    9,380
    1,912
    Nov 17, 2011
    Have you made sure the "signal" you receive with power off is really a signal from the RS232 port of the computer? Depending on the program you use for communication it may be just a local echo generated by SW on the PC.

    Another point is: you left pin 8 of U6 (R2in) open. This leaves R2in in an undefined state. According to RS232 the signals levels for defined states are < -3 V or > + 3 V.
    The undefined state may lead to the RS232 Receiver in U6 to go active at the output, thus triggering U4. In that case both RS485 transceivers U1 and U2 will be active and no signal can be transmitted via RS485. Add a pull-up rsistor (e.g. 100 kOhm) at R2in.

    For more help we will need additional information e.g. voltage levels at the DE-pins of U1 and U2, signals at U5:R1out and U6:T1in, preferably measured with an oscilloscope. When you measure these signals, you have good chances to find the source of the problem yourself.

    Harald
     
  3. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    \what is the function of NE556 in the rs485 circuit? I think RS485 does'nt need that NE556.
     
  4. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Thanks.
    Yes.It is from RS232 port.I used a program and tested it in 2 ways.
    One with RX and TX of RS232 is connected to each other and the other like what i mention above but power off.And the result i received is same.I received exactly what i had sent.
    Yes.But in this case i only simulate to transmit data :
    TX (RS232 port).-----> R1in(MAX232)----> R1out(MAX232)--->DI(MAX485)----------------RO(MAX485)--->T1in(MAX232)---->T1out(MAX232)---->RX(RS232 port)
    In this schematic I only transmit in only one direction to check my circuit.Would you show me if I need connected it and other pins that i still not used it?
    I tend to verify this schematic fist and only transmit in one direction.For other direction I will rewire it.
    Thanks.This is the measurement that I have do
    For idle state:
    TX(RS232) = -10.5V
    RX(232) = 0.03V
    DE=RE= 0V both U1 and U2.
    R1out= 5.17V
    T1in = 5.1V
    For working state:
    I regret that i have no oscilloscope right now.I used voltmeter to measure but I found that when I transmit data the voltage at TX of RS232 port is change a small amount.I vary between -7V to -9.8V
    and I sitll received exacty data when power off.
    And below is the program i had used and the result I received:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    #define TIMEOUT_CONSTANT    50
    #define ESC                 27
    
    
    
    
    int main(int argc, char* argv[])
    {
        char*s="rs232 to rs485 converter";
        int          key_pressed   = 0,i=0;
        char         outchar       = 0;
        char         inchar        = 0;
        DWORD        bytes_written = 0;    // Number of bytes written to port
        DWORD        bytes_read    = 0;    // Number of bytes read from port
        COMMTIMEOUTS tempComTimeouts;      // Our temporary time-outs for COM1
        COMMTIMEOUTS savedComTimeouts;     // Stores the original time-outs
        HANDLE       comport       = NULL;  // Handle for COM port
        DCB          comSettings;          // Contains various port settings
        char buf[25];
    
        printf("com port communication");
        printf("COM1 program\n\n");
        
        // Open COM port
        if ((comport = 
              CreateFile("COM1", 
                        GENERIC_READ | GENERIC_WRITE,          // for reading and writing
                        0,                                     // exclusive access
                        NULL,                                  // no security attributes
                        OPEN_EXISTING,              
                        FILE_ATTRIBUTE_NORMAL,
                        NULL)) == INVALID_HANDLE_VALUE)
        {
            printf("Unable to open COM1.\n\n");
            printf("Press any key to exit.");
            getch();
            return(1);
        }
    
        printf("COM1 opened.\n\n");
    
        // Save time-out parameters for COM1 
        GetCommTimeouts(comport,&savedComTimeouts);
        
        // Set our time-outs 
        tempComTimeouts.ReadIntervalTimeout         = TIMEOUT_CONSTANT;
        tempComTimeouts.ReadTotalTimeoutMultiplier  = TIMEOUT_CONSTANT;
        tempComTimeouts.ReadTotalTimeoutConstant    = TIMEOUT_CONSTANT;
        tempComTimeouts.WriteTotalTimeoutMultiplier = TIMEOUT_CONSTANT;
        tempComTimeouts.WriteTotalTimeoutConstant   = TIMEOUT_CONSTANT;
        SetCommTimeouts(comport,&tempComTimeouts);
    
        // Set Port parameters.
        // We make a call to GetCommState() first in order to fill
        // the comSettings structure with all the necessary values.
        // Then we change the ones we want and call SetCommState().
        GetCommState(comport, &comSettings);
        comSettings.BaudRate = CBR_9600;
        comSettings.StopBits = ONESTOPBIT;
        comSettings.ByteSize = 8;
        comSettings.Parity   = NOPARITY;
        comSettings.fParity  = FALSE;
        SetCommState(comport, &comSettings);
        
     
         while(1)
         {  
     
              i=0;   
              while(s[i]!=0)                                                     
                {   
                    // Send data. if succesful, WriteFile() returns non-zero 
                    WriteFile(comport,        // Handle
                              &s[i],      // Outgoing data
                              1,              // Number of bytes to write
                              &bytes_written, // Number of bytes written
                              NULL); i++;
                }
                                                                                       
            // Read data. if succesful, ReadFile() returns non-zero
            ReadFile(comport,                 // Handle
                       buf,                    // Incoming data
                       sizeof(buf),            // Number of bytes to read
                       &bytes_read,           // Number of bytes read
                       NULL); 
                       DWORD j;   
    
             printf("\n%s", buf);
             for(i=0;i<25;i++)
             buf[i]='\0';
     
       }
        // Restore time-out parameters 
        SetCommTimeouts(comport,&savedComTimeouts);
        CloseHandle(comport);
        getch();
        return(0);
    
    }
     

    Attached Files:

  5. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Thanks.In this case I used NE555 to control the DE and RE of max485.Only DE or RE is
    permit at a same time.Would you watch the orginal circuit in this:
    http://www.bb-elec.com/bb-elec/literature/485ptbr-3903ds.pdf
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    9,380
    1,912
    Nov 17, 2011
    Right, but if the RS232 receiver on the right trigggers the Timer on the right due to the undefined input both RS485 driver will operate against each other.

    Your measurement
    Code:
    DE=RE= 0V both U1 and U2.
    confirms that suspicion. Add the pull-up as I recommended. Or maybe it should be a pull-down. I'm getting confused by the different logic levels on the RS232 side and teh TTL side. Alternatively you can, just for testing, disconnect DE of the right RS485 transceiver and pull it to an inactive level.

    @RLEO: The timers serve to detect the data direction and to control the RS485 drivers accordingly. Since RS485 has only one signal (although it is differential, using two wires) only one partner can send at any time. This is controlled by the RxD signal. If an active RxD is detected on one of the RS232 ports, this determines the data direction.

    You cannot send from both RS232 ports simultaneously. This setup creates a time-multiplexed unidirectional connection.

    Harald
     
  7. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    @Harald

    Thanks for the explanation.
     
  8. Harald Kapp

    Harald Kapp Moderator Moderator

    9,380
    1,912
    Nov 17, 2011
    @RLEO:
    Sorry, it is controlled by TxD, of course. RxD is the receiving end and cannot control the data direction.

    @anhnha:
    Now I found time to look a bit more into the matter.
    DE=RE=0 means both RS485 transmitters are set as receivers. That is the idle state.
    When you send data via RS232 TxD, DE of U1 should go temporarily high to enable transmission. If this doesn't happen, check the timer circuit U3 and the related components and wiring. U1 should be triggered by the rising edge of the data at pin 2.

    Harald


    Harald
     
  9. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    @Harald

    Your correct. Most of our RS485 circuit does not use NE555 because RE and DE were tied to controlling output of a SIO controller.
     
  10. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    @anhnha

    Did you mean that you can send loopback signal to rs232 port with breadboard connected and have no power? That's interesting.

    How about isolate first.

    1. Remove your rs232 / rs486 breadboard and run your loopback program. You should not receive signal.

    2. To test if your RS232/RS485 circuit was working.Remove breadboard from PC connection. Apply +5 volt supply to your breadboard. Then manually simulate RS232 signal voltage to RS232 RX input. You can use the - and + ( alternately reversing it ) of battery as signal to RX input of RS232 connector. You can series a 470 resistor to battery to as short circuit protection.
    You can monitor the TX output of connector with your DC Voltmeter. You can also troubleshoot your breadboard components with the said "manual signal".
     
  11. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Thanks for all help.
    I had debug my circuit step by step and there are several things make me confuse.

    At first I had used the circuit of convert file[attached in this] to transmit data.With TX is tied to R1in of U5 and RX is tied to T1out of U6.Then i used the code that i had posted previously to transmit and received to/from com port.Then I am supprising that I can receive exactly data without power supply.
    In order to debug the circuit I checked all components.First, all components in
    the circuit is removed except max232.
    I put max232 into breadboard without any capacitors and power is used.After there is a strange problem that I can not understand and i think this is my problem.
    The strange is that when I tied TX to one pin and RX to another pin of max232 and both 2 pins is can be any pin of max232, then if i run program to transmit and receive data to/from com port, the data in received exactly what to be sent.
    I seem that all max232 pins is connected to each other result in TX and RX pins is connected to each other.
    At fist thought, I think the Max232 is blown but when I checked it under the guide below, all results is relative right.
    This is the guide to test max232:
    "Power up the MAX232 and check voltage across supply pins to insure correct voltage input.
    The following two tests check each "TTL in - RS232 out" converter.
    Put 0 volts into pins 10 and 11, then check pins 7 and 14. Should have about 10 volts output on each.
    Put 5 volts into pins 10 and 11, then check pins 7 and 14 again. Should have about -10 volts output on each.
    If that succeeded, then check each "RS232 in - TTL out" converter. Connect pin 7 to pin8. Connect pin 13 to pin 14. This will be a "loopback test".

    Put 0 volts into pins 10 and 11, then check pins 9 and 12. Should have about .6 volts output.
    Put 5 volts into pins 10 and 11, then check pins 9 and 12 again. Should have about 4.5 volts output."
    There it is make me confuse that in the circuit when i tied TX in one pins
    it is appearded that all pins is connected each other and I received data exactlly without power supply.
     
  12. Harald Kapp

    Harald Kapp Moderator Moderator

    9,380
    1,912
    Nov 17, 2011
    From the datsheet:
    This is a common input protection scheme. As soon as the input voltage on a pin exceeds GND or Vcc by ~0.5 V, the diodes become conducting thus limiting the voltage for the internal circuit of the IC.
    This means that without operating voltage the pins are connected with a series impdance of a few kOhm. This may be enough, in your case, to produce a signal that is read by the PC.

    You can debug your setup step-by-step:
    1) remove the timers (555 / 556), Enable DE on the RS485 transmitter and RE on the RS485 receiver by adding pull-up or pull-down resistors. You now have only one direction to test. Work through the circuit until it works.
    2) Add the timer for the transmit direction. The circuit should still work. If not, locate the problem with the timer. You may need an oscilloscope to observe timing and waveforms.
    3) When thr transmit timer works, perform the same steps for the receive timer.

    By the way: Your circuit seem to miss a proper termination. Look here: http://en.wikipedia.org/wiki/RS-485 A few resistors suffice. You need that termination only once.

    Harald
     
  13. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Thanks for your explaination.
    This knowledge is new to me.
    I have debug my circuit step by step as your guide.You are right.When i set DE to high in transmitter and RE to low in receiver, the circuit work well.But when i add 555 timer in the circuit i also received data but it is not exactly, all character is wrong.Would you tell me what should i do?
    In the schematic I have set up a 555 timer in monostable mode..In this both C1 and C2 capacitor are 10nF.The the pulse is 1.1x100K.10nF=1.1ms
    In this case, I used the baud rate is 9600bps, therefore the time to transmit each bit is 0.104 ms and one byte with 10 bits will take 1.04ms.I think that this config is right for 555.
     
    Last edited: Apr 30, 2012
  14. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    I am sorry, I miss a connection, now i receive data it is not exactly but about 70% right.
     
  15. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    You should use RS232 standard software or hardware and handshaking to avoid missing bits or data.
     
  16. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Could you tell me do i really need connected all pin of max485 that is not used.For example, I
    used max485 in receiver side, and I set RE and DE to low level and RO is connected TTL inputs of max232, and DI is not connected anything,I understand max232 function in general but I do not know if max485 operation in receiver mode is effected by DI or not?
     
  17. Harald Kapp

    Harald Kapp Moderator Moderator

    9,380
    1,912
    Nov 17, 2011
    Unused inputs should always be pulled up or pulled down to a defined logic level. This is good practice.
    Also you should follow Rleo's advice and debug the circuit using a standard program. Any teminal program (e.g. hyperterm on Windows XP) can do the job.
    Only when the circuit is stable you should start debugging your program.
    Of course you can do it the other way round: Connect TxD and RxD of the Computer's Rs232 and first debug your program. Once the program is stable, insert your circuit and debug this.

    In my experience it is almost always advisable to debug step by step and not to have too many variables. You never know how they influence each other.

    Harald
     
  18. anhnha

    anhnha

    14
    0
    Apr 26, 2012
    Thanks all help.
    At last my circuit have successed.I think the main problem is from the use only one computer to test.I found that the TX pin have to connected to DI pin of 2 max485.
     
  19. Rleo6965

    Rleo6965

    585
    9
    Jan 22, 2012
    Happy to hear for your successful project.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-