How to receive stream of bytes using PIC USART


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    OK - it has only one stop bit. It appears that various manufacturers use their own protocol.

    60 packets per second x 5 bytes per packet x 10 bits per byte = 3000 bits per second which, at 4800bps, means 30 (or fewer - depends on pace) idle bit-times between packets.

    I would capture 10 bytes, scan them for the first initial byte (>127) and then look at the following 4 bytes for your data.

    EDIT: 9 bytes would guarantee one complete packet.
    Last edited by dhouston; - 16th June 2009 at 17:10.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hmm, seems that is like the pdf I posted. Is it the same module?

    Based on the infos and the idea of Dave's:

    Code:
    array    var   byte[9]
    temp    var   byte
    i          var   byte
    j          var   byte
    
    get_new_data:
    SerIn2 PORTB.7,16572,[str array\9]
    for i=0 to 8
        temp=array[i]
        if temp.7=1 then goto send_at_9600
    next i
    hserout ["Not found!",13,10]
    goto get_new_data
    
    for j=i to i+4
    hserout [array[j]]
    next j
    
    goto get_new_data
    
    end
    Hope this will get you started. Don't forget the defines for the Hserout command to set it at 9600.

    Ioannis

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    You need only scan the first five bytes to find the start of a packet. And you can save one step on each loop.
    Code:
    for i=7 to 39 STEP 8
        if array[0].i=1 then goto send_at_9600
    next i
    Last edited by dhouston; - 17th June 2009 at 16:03.

  4. #4
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Thanks for the suggestions, but the result I get is still not correct.

    Have anyone tried to send an endless stream of bytes to PIC and then resend the stream back to PC? Will the input bytes same as the output bytes?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Please post you complete code as is now.

    Of course the PIC will send the correct bytes as received, why shouldn't??

    Ioannis

Similar Threads

  1. Replies: 6
    Last Post: - 31st August 2007, 09:31
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. 16F876 Usart Receive
    By syscoder in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st March 2007, 15:43
  4. Replies: 1
    Last Post: - 6th September 2005, 16:32
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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