receive ASCII with usart


Closed Thread
Results 1 to 4 of 4
  1. #1
    harryweb's Avatar
    harryweb Guest

    Unhappy receive ASCII with usart

    HI,

    I'm trying to use the USART of a 16f876. I have a problem

    I need to receive more than one character...
    By example: I can receive "B 01234" or "F 65495" or " F +"....

    I have no problem to receive the 1st character (with the sample melabs prog given) but I can't find any example for 3 to 7 characters.

    I can't use the serin2 command !

    If someone can help !

    Regards

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi harryweb,

    There can be any number of things to consider when receiving data with the USART. But if the first 2 examples you presented were the normal sequence of bytes being received, something like this might work.

    Code:
    B1  var  byte  ' First character
    B2  var byte  ' space
    W1  var  word  ' Value received
    
    loop:
      HserIn [B1]
      if (B1 <> "B") and (B1 <> "F") then loop
      HserIn [B2, DEC5 W1]
    Now B1 holds the first char, and W1 has the value (0-65535)

    Of course, this assumes that the data stream is always in the same format. If it differs from packet to packet, you'll need to think harder about how to capture all the variations. And then there's timeouts you can add, in case something goes wrong, the program can still go on working, instead of just sitting and waiting for data that will never come.


    Darrel

  3. #3
    harryweb's Avatar
    harryweb Guest


    Did you find this post helpful? Yes | No

    Question USART

    Thank you DARREL
    The problem is also:

    I don't know when something could be received and my program can't wait for a character. (It has something else to do)
    If some characters arrive when my prog is not ready to receive, (out of a timeout) these characters are lost ?

    Regards

    HERVE

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, then it sounds like it's time for an interrupt driven serial receive buffer.

    Here's one example from Tim Box, using INSTANT INTERRUPTS. It might be a good start for you. Check out the TXT files in the zip for a description of how to use them.

    http://www.pbpgroup.com/files/INT_CTRL.zip

Similar Threads

  1. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  2. Replies: 6
    Last Post: - 31st August 2007, 09:31
  3. 16F876 Usart Receive
    By syscoder in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st March 2007, 15:43
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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