How to receive stream of bytes using PIC USART


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    The SpO2 module I use is of none parity.

    I wonder the PIC have the problem to read the bytes if the bytes are sent into PIC in endless stream. I tried to send only 5 bytes, 10 bytes and 15 bytes data in SpO2 module's data format and the PIC can process well using the code I wrote.

    Then I tried to let PIC sent out each byte it read in from a endless bytes stream. The output of the PIC is different from the data it read in.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by unifoxz View Post
    The SpO2 module I use is of none parity.
    That's not the issue. How many STOP bits is the issue. If, as the only reference I could find for the BCI protocol says, it uses 8N2, you cannot handle it - all of the PBP methods require 1 stop bit. Two stop bits could explain the erratic results. You need to provide a link to the datasheet for the specific SP02 device you are using.
    Last edited by dhouston; - 16th June 2009 at 11:56.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    You need to provide a link to the datasheet for the specific SP02 device you are using.
    I double that, although have asked for it earlier.

    It seems you loose synchronization. But we are only guessing here as we have no informations about you device.

    Ioannis

  4. #4
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    I try my best to translate the manual as the manual is originally written in Chinese language. The manual is too simple and not really provides the details.

    serial port setting:
    • 1 start bit + 8 data bit + 1 stop bit, no parity
    • baud rate: 4800 baud
    • 5 bytes format, 60 packages per second, bit 7 is the synchronous bit

    byte 1:
    • bit 7: synchronous bit, as 1
    • bit 6: 1=instruction for pulse sound
    • bit 5: 1=SpO2 decrease, 0=OK
    • bit 4: 1=searching time too long, 0=OK
    • bit 3-0: signal strength (0-8), represent signal strength of pulse

    byte 2:
    • bit 7: synchronous bit, as 0
    • bit 6-0: pulse wave diagram

    byte 3:
    • bit 7: synchronous bit, as 0
    • bit 6: pulse rate bit 7
    • bit 5: 1=search pulse, 0=OK
    • bit 4: 1=sensor error, 0=OK
    • bit 3-0: pulse bar diagram

    byte 4:
    • bit 7: synchronous bit, as 0
    • bit 6-0: pulse rate, (bit 6 to bit 0)

    byte 5:
    • bit 7: synchronous bit, as 0
    • bit 6-0: SpO2

  5. #5
    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.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    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

  7. #7
    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.

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