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

    It's repeating 5 bytes. 5 bytes continued by another 5 bytes without pause, all are sent out continuously. In order to get the SpO2 byte and pulse rate byte which is at the 4th and 5th byte from the header byte (the byte with synchronous bit = 1), I need to read in 9 bytes as if the first byte I get is the 2nd byte of the 5 byte. So the header byte will be at the 5th byte and the SpO2 byte and pulse rate byte will be at the 8th byte and the 9th byte.

    It's like this:
    2, 3, 4, 5, 1 (header byte), 2, 3, 4 (pulse rate byte), 5 (SpO2 byte)

    All the data is in hex format, no specific 0-9-A-Z.

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


    Did you find this post helpful? Yes | No

    Default

    I cannot imagine a device keep sending a blast of bytes without any synchronization!

    Please give us a link for the data sheet or if small post it here.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    Many devices send continuous blasts of data.

    Here's a definition for spo2 http://www.neann.com/spo2.htm. A manual for the specific device would be helpful.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    I did a little search in the web and found that the modules for medical applications use the so called BCI protocol with 4800 8-ODD-1 serial setup.

    Data frames are 5 bytes long and on the first byte the 7th bit is 1 while on the restbit 7 is set to 0.

    So, may be you get one byte at a time and check the bit 7 only for it to be 1. Then get the rest and store in a byte array of 5 elements.

    If there is not a sync byte or a significant pause between frame transmissions, PIC cannot discriminate the start byte. That is why you get confussing results.

    One untested example might be:

    Code:
    array    var   byte[5]
    index    var   byte
    
    index=0
    get_new_data:
    SerIn2 PORTB.7,16572,[B0]
    if B0.7=1 then
        array[index]=B0
        index=index+1
    endif
    
    if index=5 then process_data
    
    goto get_new_data
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    I did a little search in the web and found that the modules for medical applications use the so called BCI protocol with 4800 8-ODD-1 serial setup.
    Where did you find the protocol description? The only reference I found indicated it uses two stop bits.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Dave. I found the attached pdf that is implying the protocol.

    Ioannis
    Attached Images Attached Images

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

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

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