+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2017

    Default hserin buffer fills before all characters can be read

    I am interfacing to an Elo touch screen for a custom solution. The elo messages are suppose to always be 10 characters long and start with the character U. I want to be able to capture all 10 characters in an array but only start when the "U" is received. I can do this utilizing a for next loop or even a STR VaraibleName\9 modifier however I have a few issues with these methods.
    1 What if the two system turn on out of sync and the PIC18f24K22 starts to receive in the middle of a message?
    If my code always expects 10 characters it will then always be out of sync
    2 What if for some reason communications are lost, then the loop gets stuck, it needs an exit.

    I should add, the communications is asynchronous and using only the TX/RX pins, 9600/8/n/1

    I wanted to have
    hserin 100, main, [char[0]] 'if there is no message then go back to main program
    if char[0] = "U" then 'if there is a message AND it is the beginning of the message, then capture the rest of the message, but at this point, the buffer is full
    for i = 1 to 9
    hserin 100, exit, [char[i]]
    next i

    However, when i use this, the buffer fills up before I can collect any other characters. I expected the execution time (I am using the internal oscillator and running at 16 mhz) to be quick enough to grab each character before the buffer filled up. The above method will get the first two characters, then fill up. I then send more characters which are captured. I tried adding an rcsta.4 reset as follows, however that didn't solve any of my problems.

    hserin 100, main, [char[0]]
    rcsta.4 = 0
    rcsta.4 = 1
    if char[0] = "U" then
    for i = 1 to 9
    hserin 100, exit, [char[i]]
    next i

    I would appreciate any suggestions on an approach which will allow me to get in sync with the elo and handle the rather small buffer.


  2. #2
    Join Date
    Jan 2006

    Default Re: hserin buffer fills before all characters can be read

    Hserin [WAIT("U"),STR IncomingData\9]
    'This one waits forever for the correct string to arrive.
    Hserin 100, Jump, [WAIT("U"),STR IncomingData\9]
    'This one waits for the correct string for 100ms and then if not received jumps to Jump label.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2017

    Default Re: hserin buffer fills before all characters can be read

    Thank you. I wasn't aware that you could combine the Wait with the timeout. That works very well.


Similar Threads

  1. hserin buffer
    By aarothepharo in forum mel PIC BASIC
    Replies: 8
    Last Post: - 6th May 2013, 10:27
  2. Read write word and Hserin
    By aa222k in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st December 2011, 19:27
  3. read bytes number in Hserin
    By Rony in forum Serial
    Replies: 13
    Last Post: - 13th August 2010, 10:32
  4. Only the first 8 characters.
    By timseven in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd September 2009, 01:43
  5. Replies: 3
    Last Post: - 12th February 2007, 18:32

Members who have read this thread : 0

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