HSERIN and internal buffer problem on 16F628


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2007
    Posts
    39

    Thumbs up HSERIN and internal buffer problem on 16F628

    Hello,
    sorry maybe I am too stupid but seems I have a problem even with the basic operation of HSERIN to receive the data, I don't know, how to solve it.
    Immagine, that I want to simple receive two variables from my terminal, I cannot manage the timming:
    E.g. I want to send p123 and I want to have it in two byte variables:
    in one variable the ascii code of p and in second variable the value 123.

    Looks easy, what I simple tried to do:
    COMMAND var byte
    SERIALBYTE var byte

    while 1
    if (PIR1.5==1) then
    HSERIN 10, jump [command, DEC SERIALBYTE]
    gosub managebytes
    endif
    :jump
    wend

    The problem is, that this doesn't work and I always have in command == "p" and in SERIALBYTE = 1.
    I think, that the reason is, that the buffer of the pic has only two bytes for the serial buffer, so when I sent these 4 bytes, only first two are stored and saved to the buffer and PBP is not fast enough to manage it. My PIC is working only on 3.5 Mhz..... Do you have any other idea, how could I receive safely several bytes not just 2? I cannot use other PINS then RX and TX, so the HW flow control cannot be used.

    Thanks Robert

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    how about
    Code:
    HSERIN 10, jump [command, DEC3 SERIALBYTE]
    Could you post the whole thing here?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default

    Hi,
    I was just about to make the same sugestion as Steve. But looking at the manual it actually says that if no number follows the DEC modifier it will receive as many digits as it gets. So I'd say it should work as it is (except the missing comma after jump).

    Is your X-tal 3.5Mhz or 3.58Mhz? (Can't seem to find a 3.5Mhz so I'm guessing 3.58Mhz). Have you informed PBP of oscillator speed?
    Code:
    DEFINE OSC 3     '<---This assumes a 3.58Mhz X-tal
    And how is the USART baud rate generator setup? With PBP defines or 'manual' ?

    Please, try adding 3 to the DEC modifier as per Steves post and let us know if that helps. If so there seems to be an error in the manual.

    /Henrik Olsson.
    Last edited by HenrikOlsson; - 12th February 2007 at 18:15. Reason: Spelling...

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    DEC may work or not, depending how your terminal will send your data. If he send CR+LF, this will screw your data for sure.

    i've tried with
    Code:
    Command     var byte
    SerialByte  var byte
    
    hserout ["---- Ready ----",13,10]
    Start:
            while 1
                if pir1.5 then
                    hserin 10,jump,[Command, DEC3 SerialByte]
                    gosub ManageBytes
                    endif
                Jump:
                wend
            goto start
    
    ManageBytes:
            hserout ["Command=",Command,_
                     "   SerialByte=", #SerialByte,13,10,13,10]
            return
    And it's working just fine, with terminators (CR+LF) or not

    depending of your Baudrate, 3.58 MHz may work fine or not. Worth to use the PicMultiCalc to see the error %
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Hserin with Instant Interrupts.
    By ronjodu in forum Serial
    Replies: 17
    Last Post: - 30th December 2014, 20:17
  2. LCD serial backpacks
    By Archangel in forum Serial
    Replies: 67
    Last Post: - 30th December 2010, 04:51
  3. HSERIN / SERIN Problem with 16f690
    By rborsuk in forum Serial
    Replies: 24
    Last Post: - 5th February 2010, 04:51
  4. PC to EUART on pic 16F688
    By docaberle in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 25th October 2008, 06:33
  5. 16F877a Interupt driven Hserin
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd November 2006, 00:38

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