[SOLVED !] Invisible RS232 Serial Buffering code of Les and RS485


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Invisible RS232 Serial Buffering code of Les and RS485

    I have used for years the fantastic routine offered by Les and updated by Tim.

    Thanks again Les and Tim.

    Now I need to exchange data between the PC and more that two 18F4550. I'm using one USB adapter to have the RS485 on the PC side and the small adapter with inside the MAX 485 to the PIC side.

    I'm able to transmit from PIC to PC, but Im not able to receive data send by the PC to the PIC.

    No one character enter into the buffer.

    Consequently the way to see the lenght of the input buffer like below is not good.


    If _USART_BUFFER_COUNT > 0 Then 'check if any character is arrived on the UART
    GoSub Receive
    EndIf


    Please point me in the right direction to understand how to receive data from RS485.

    Attached please find the code that I'using with the original include file from Les containing the small modifications suggested by Tim.


    Leo
    Attached Files Attached Files

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Are you converting the RS485 to RS232 with a chip so the PIC can receive as before?


    Norm

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Hi Norm,

    you suggestion push to me to make parallel debugging with the same routine working with RS232 and on the new HW with RS485 and I have dscovered that the adapter USB to RS485 do not work well. I spend all the yesterday an part of today to try to found the problem, finally I have realized that there are a problem with the adapter. From the adapter do not came out TX data. He receive only data from the PIC.
    In reality I do not have understand if is a problem of driver or other things. I'm investigating now.

    The adapter that I use is the LX08A.

    Inside the adapter there are the CH340 for the USB part and the Max485.

    Click image for larger version

Name:	USB-RS485_LX08A .JPG
Views:	12
Size:	23.9 KB
ID:	3075

    I have found different release of driver on the web and I'm testing it.

    I will inform about the results.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Is the PIC pin wired to receive RS232 or RS485?

    Norm

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Hi Norm,

    The 18F4550 is leaved set up to receive RS-232 for two main reasons:


    - 1: The set up of the registers for the 9 bit mode as the reference in data sheet "20.2.3 SETTING UP 9-BIT MODE WITH ADDRESS DETECT" seems to difficult to implement at thie early stage.

    - 2: From the side of Win10 with VB2012 how to send data with 9 bit.? (Using fake parity bit?)


    I suppose that now, continuing to use the PIC in the RS-232 mode all shall be simple.

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    The reason I ask is to my knowledge a PIC cant read RS485 with RS232 hardware as the two are differing voltages etc..

    Norm

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Hi Norm,
    sorry to have generate misunderstanding, but the English language is not my mothertongue and Google translator assist me a lot.

    Shall be better to say:

    From the point of view of the PIC and Les procedure, if the TTL signals connected to the UART come from a MAX485 or MAX232 is exactly the same.

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Quote Originally Posted by wirecut View Post
    Hi Norm,
    ...From the point of view of the PIC and Les procedure, if the TTL signals connected to the UART come from a MAX485 or MAX232 is exactly the same...

    Leo
    Yes perhaps others could confirm if the above statement is true?
    I have some doubt as they differ in voltages for starters and would at least require some configuration changes.
    The answer is more than likely in the datasheet.


    Norm
    Last edited by normnet; 2nd July 2016 at 17:54.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    493
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    408.14 MB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Yes, it's correct for the most part.

    RS232 or RS485 apply to the signal levels, and I think wirecut is saying that he's using a MAX485 transceiver.
    Usually when using RS485 you set the uart for 9-bit mode (8 data bits + a bit to signal addr/data), but it can be used in the normal
    8-bit setting of the uart as well (what he's calling "RS232" mode).

    As long as both ends are using the same protocol it would work fine. What usually trips things up is that RS485 is typically used in half-duplex
    (it transmits and receives over the same set of wires) where RS232 has TX and RX signals.

    For 485 half-duplex you have to control the direction of the transceiver as appropriate.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    My question is if there is a MAX485 transceiver at the PIC end?

    Norm

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Hi Norm,

    yes, I use a TTL to RS-485 converter at the PIC side as the below image:

    Click image for larger version

Name:	RS485_TTL.JPG
Views:	11
Size:	38.6 KB
ID:	3076

    There are connected together the DE and RE to the I/O port RS485TX and I manage the transmission as follow:
    Code:
    Symbol Key1 = PORTB.0        ' Key1
    
    If Key1 = 0 Then
      If Key1 = 0 Then  High  Beeper 
      Low LED_D2
      High RS485TX                ' Enables the transmission and inhibits the reception
      DelayUS 20                                  
      HRSOut "H "
      DelayUS 200                                    
      
      Low RS485TX                 ' Enables receipt and inhibits the transmission
      DelayMS  20                 ' during this time will be managed the data exchange
      High LED_D2   
      Low Beeper
    EndIf
    Then I write a simple protocol to polling all the PIC and only one PIC at time can answer to the polling.
    Each PIC will have its proper and unique address written into the FLASH.

    After sending the poll with a specific address, the PC wait a time slot to receive the answer from the selected PIC before continuing the polling. Into the time slot can be exchange the data as usual.

    More or less that is a simplifies and revisited protocol of communication of the old IBM3270 teleprocessing system used in '70 years.

    At this phase is not needed a fast interaction between the PC and the PIC because is needed to transfer a very low quantities of data between the PC and the 8 PIC that compose the small network.

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    493
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    408.14 MB

    1 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    When working with RS485 there are a number of things to be aware of.

    First, when the receiver is disabled (RE = 1) the RO receive data out of the transceiver is high-impedance,
    so the RX input of the pic is floating. This can cause issues with the pic uart. If the RX input is seen as
    a low then that will generate a serial break condition and/or framing errors that must be dealt with.
    This pin should have a pullup resistor so that when RE=1 the RX pin is seen high, which is the idle state for the uart.

    Likewise, on the RS485 side of the transceiver you can have issues when the transmitter is disabled (DE = 0).
    The Y and Z outputs will be floating, so depending on the transceiver used and any termination resistors this can
    cause the signals at the other end to be unknown. Some transceivers are setup to deal with this, but it's very
    hardware dependent. It's common to have a pullup on the A (non-inverting) line and a pulldown on the B (inverting) line.
    This establishes a failsafe bias for the idle condition. Check the datasheet for the transceivers to see if this
    is an issue, and be aware that the 120 ohm termination resistor can defeat any internal failsafe the chip might have.

    Looking at the RS485_TTL.jpg image it looks like that adapter possibly has the idle state biasing (R5 and R6) and
    termination resistors (R7), but it's hard to tell without a schematic. It might even have pullups on the pic side (R1-R4 10K),
    but again, it's hard to tell.

    One thing I like to do is to not tie the RE and DE signals together, but to always enable the RE. That allows you to see
    what you transmit (you get a local echo) and you can use that to control when to disable the TE signal instead of inserting
    pause statements after you transmit. That way you don't have to have different delays for different baud rates.

    It also gives a poor mans "collision detect" capability as you can now see if another device transmits while you do.
    This isn't foolproof, as there can be a difference in what the drivers see at both ends if you're working at long distances,
    but many times it's better than nothing.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Dear tumbleweed,

    many thanks for the valuable tips you have given. I'll keep good account during the development of this project.

    Let me ask you, how do you control and how check the local echo and how to recognize when the transmission end?

    In relation to the RS485 to TTL adapter, I thought a couple of macro images that allow easily to reconstruct the schema and component values.

    Click image for larger version

Name:	RS485TTL_Upper.jpg
Views:	21
Size:	96.4 KB
ID:	3081
    Click image for larger version

Name:	RS485TTL_ lowerJPG.JPG
Views:	12
Size:	94.9 KB
ID:	3080

    I can see that the 120 Ohm value is there.

    The chip is a Max485.

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    493
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    408.14 MB

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Click image for larger version

Name:	lctech rs485 schematic.jpg
Views:	33
Size:	22.0 KB
ID:	3082

    Here's the schematic of the LC-TECH module. As you can see it has 20K idle state biasing on the A-B lines, a 120 ohm termination, and 10K pullups on the pic side of the transceiver. That's nice... nothing floats. About the only complaint is that there's no GND available on the screw terminal blocks, just the two data lines.

    If you enable the receive data output (RE=0) then you can receive every byte you transmit. You know when the transmitter is done when you receive the byte, and unlike using most of the uart tx status bits to try and detect this you'll know that the entire byte + stop bit(s) have been transmitted and you can disable DE.

    You want to disable the transmitter as soon as possible, otherwise you end up with a potential race condition if the slave tries to transmit a response before you have the master transmit disabled. Arranging it this way means you don't have to hard-code delays into your protocol on either end.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #15
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Invisible RS232 Serial Buffering code of Les and RS485

    Hi tumbleweed.

    Many thanks for you precious suggestion.

    I have a question about the network.

    I will have eight slave and one master.
    The distance between the master and the first slave is around one meter and half and the distance between the first slave and the second slave is around 20 cm or less. Then the distance between the second to the third slave is the same, 20 cm and that distance between the slave will be the same for all eight slave.
    That means the total distance of the network shall be less than 4 meters.

    About the 120 Ohm resistor, it shall be removed on all slave PCB and remain only on the master and on the last slave?

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Invisible RS232 Serial Buffering code
      By top204 in forum Proton Plus Compiler v3
      Replies: 142
      Last Post: 16th January 2018, 09:02
    2. Serial Port/RS232
      By Jessica in forum Projects discussion
      Replies: 4
      Last Post: 21st October 2014, 19:28
    3. RS232 & RS485 on same port
      By pic-ignorant in forum The Lounge
      Replies: 1
      Last Post: 27th November 2011, 20:11
    4. USB to serial RS232
      By Ken_K in forum The Lounge
      Replies: 10
      Last Post: 1st October 2011, 13:32
    5. Invisible RS232 Serial Buffering code By Les
      By PAKirk in forum The Lounge
      Replies: 9
      Last Post: 23rd June 2011, 20:44

    Members who have read this thread since 14th December 2019, 15:34 : 0

    Actions :  (Set Date)  (Clear Date)

    You do not have permission to view the list of names.

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts