SerIn2 ASCII Conversion


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    dear rwskinner

    thank you for your reply.
    at least can you please give me a working code for generating CRC for modbus RTU (in PICBASIC Pro)

    assuming that i have received from the HSERIN these byte

    BYTe_1 BYTe_2 BYTe_3 BYTe_4 BYTe_5 BYTe_6 CRC1 CRC2

    for example

    01 03 00 00 00 0A C5 CD

    how to calculate the CRC1 and CRC2

    i am using this with PIC16F877A

    Best Regards

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mech962784 View Post
    dear rwskinner
    thank you for your reply.
    at least can you please give me a working code for generating CRC for modbus RTU (in PICBASIC Pro)
    Best Regards
    Did you look at your other thread? There's code already there...

  3. #3
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Yep, it was in the thread that said "working Code"

    Here is my method of CRC which I believe came from that thread ???
    And my method of LRC which works but could be improved upon.

    Notes:
    CRC is a WORD, LRC is a Byte
    Buf is an array that contains all the bytes.
    Len is the number of bytes in the array and you set that depending on what your doing.
    When Receiving messages LEN has to be adjusted to Exclude the CRC or LRC Bytes.



    CalcCRC:
    CRC16=$FFFF
    For i = 0 to Len
    CRC16=CRC16^Buf[i]
    For j = 1 to 8
    IF CRC16.Bit0 = 1 Then
    CRC16=$A001^(CRC16>>1)
    ELSE
    CRC16=CRC16>>1
    EndIf
    Next j
    Next i
    Return




    CalcLRC:
    'Procedure Builds LRC value from bytes
    LRC = 0
    For i = 0 TO Len
    LRC = LRC + Buf[i]
    Next i
    LRC = $100 - LRC
    Return

  4. #4
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    by the way: dear rwskinner

    which company are you working for?
    have you implemented the can or canopen protocol using the picbasic?
    can you give me the specification of these two protocols?so i can do the implementation.

    best regards

  5. #5
    JohnR's Avatar
    JohnR Guest


    Did you find this post helpful? Yes | No

    Default Modbus (slave) 16F877A

    Did you finally get a working solution for Modbus ?
    I saw a lot of banter and pieces but I need a simple, complete source code in PicBasic and or assembly for PIC16F877A

    If so would you share it or where can I get it

    Thank You

  6. #6
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    There was actual working code in the links I posted above. These are not my sources but the code works.
    Mine doesn't look anything like that however the CRC Routine was borrowed from it.

    Also in the thread right next to this one called something like RS485 network
    Last edited by rwskinner; - 4th March 2008 at 23:00.

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 10:47
  2. ASCII to Long conversion
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th March 2009, 00:43
  3. ascii conversion help needed
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 13th January 2007, 07:33
  4. Hanging on SERIN2 - SOLVED!
    By blainecf in forum Serial
    Replies: 1
    Last Post: - 13th July 2006, 18:55
  5. Conversion of 10-bit word into ASCII
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th January 2005, 15:26

Members who have read this thread : 0

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