Simple question about Serin..


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2007
    Posts
    3

    Default Simple question about Serin..

    Hello,

    I'm writing some code for a couple of 16F628's on a RS485 network..

    I'm using the serin command ;
    Code:
    databyte      VAR    BYTE    ' Recieved command/request
    ADRESS        VAR    BYTE    ' Adres selected by dip switches
    
    serin PortB.1,t9600,[WAIT (ADRESS),databyte]
    The adress is selected by an 8 bit dipswitch on the slave pcb.
    The only way a slave can be adressed is by its unique adress.

    I now want to implement a broadcast adress to..

    I was wondering if there is a way so that the slave only completes the serin command if the "adress" statement OR the "broadcast adress" is forfilled ?

    I've tried ;
    Code:
    databyte      VAR    BYTE      ' Recieved command/request
    ADRESS        VAR    BYTE      ' Adres selected by dip switches
    BROADCAST     CON    %11111111 ' Broadcast adress
    
    serin PortB.1,t9600,[WAIT (ADRESS OR BROADCAST),databyte]
    But i knew this would be to easy..

    Any help would be greatly appreciated.

    Regards Donat

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looks like your syntax is the problem.
    Code:
    serin PortB.1,t9600,[ADRESS],databyte
    It waits for whatever is in the []

    You are coded more for SERIN2

    What 485 converter are you using?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default My mistake

    Sorry, thats my mistake

    It was originally a serin2 command..

    But it's about waiting for one qualifier OR the other i'm trying to implement.

    It should store the recieved byte once the slave's individual adress (qualifier 1) or the broadcast adress (qualifier 2) is forfilled.

    Maybe i should just divide it up in two different commands..

    Thank you

  4. #4
    Join Date
    Nov 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default RS485 Tranciever

    The RS485 Tranciever i am using is the TI SN65HVD06D 1/8 Load, 10Mbps

    http://focus.ti.com/lit/ds/symlink/sn65hvd06.pdf

  5. #5
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    'Instead of waiting, grab the first byte and see if it's for your ID or Broadcast then
    'if so collect the rest of the bytes

    HSerIn Timeout,ExitRx,[BufRX(0)]
    If ((BufRx[0] = MyID) or (BufRx[0] = BroadCast)) then
    For Cnt = 1 to 7
    HSerIn Timeout,ExitRx,[BufRX(Cnt)]
    Next Cnt
    EndIf


    WAIT actually has to look at each byte as well in order to know weather to start storing or not.

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    You can use Skinner's technique which is easy enough or consider this.

    If your command sequence is terminated with a known value like CR or CRLF which is the norm in most cases, your job becomes easier. What you have to do is just collect the data and buffer it till you hit the CR. Then, check the packet for ID and process accordingly. This is how I do it in my products
    ID xxxx CR
    If the packet is not yours and not a broadcast, discard it.

  7. #7
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Yes, but if he is doing something like modbus for instance, he only has the node#, correct number of bytes to collect, and then the timeout or Silent time.

    Then he would have to verify the data with a crc check before proceding, this of course is if he is using MB RTU and Not ASCII, or his own home grown protocol.

    Only reason I menioned modbus is because he mentioned a 485 network, Node ID, and Broadcast so it kind of sounds like it.

    Richard

Similar Threads

  1. serin question?
    By sachymo in forum General
    Replies: 5
    Last Post: - 27th July 2008, 10:04
  2. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 18:27
  3. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 22:02
  4. Simple question, I hope? (Serial control, 16F84A)
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st December 2005, 19:47
  5. Replies: 4
    Last Post: - 7th September 2005, 14:11

Members who have read this thread : 1

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

Posting Permissions

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