How to receive stream of bytes using PIC USART


Closed Thread
Results 1 to 35 of 35

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    I don't use MAX232 for this circuit. I use a 22k resistor at Rx pin and 1k resistor at Tx pin. May I know is there any effect for not using MAX232? There is another question that I would like to know: can MAX3232 be used to replace MAX232?
    Yes, I used a 232. From the PIC Hardware Serial to a PC some kind of level inverter is needed. The PICs sends in true mode while PCs use inverted. It is a hardware thing that can not be fixed in soft ware . That is why we have SERIN/2, bit banging a "virtual serial poer".

    I think the 3232 will also work but I have not used one to be sure about it.

    If the module is always sending a 1,then use that in the WAIT part, grab what you need after that. What are the possibilities for the remaining data? 0-9-A-Z?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Dave, by 1 he means that the first bit of the first byte is "1" and the rest are first bit "0".

    So wait cannot be used just like that.

    unifoxz:
    What is the repeat rate of the bytes? 8 bytes at 4800 and then a pause of some seconds or milliseconds?

    You might just wait for the current transmission to finish, as you may have missed the begining of it, then wait for the pause state and grab the next 8 bytes.

    But wait, you now say it is 5 bytes? At your first post I noticed you tried to get 8 bytes of data, right?

    Ioannis

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

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


    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

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

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


    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

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

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


    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

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