HSERIN command - Still searching for answers


Closed Thread
Results 1 to 9 of 9
  1. #1
    electronicsuk's Avatar
    electronicsuk Guest

    Default HSERIN command - Still searching for answers

    I need to make use of the USART module on a 16F627. I have tried a number of times but I can't get it to receive anything. Note that I am not bothered about transmitting. I have a feeling it's not working because I have not set some registers that relate to the USART, but I have no idea what they should be set to. I basically want to receive 2 bytes of serial data, and read them whenever I am ready. I took a look at the datasheet, but I still stand confused. If someone could give me some example code or tell me what registers to set, and what to set them to, it would be very much appreciated.

    Many thanks,
    Matthew

  2. #2
    's Avatar
    Guest


    Did you find this post helpful? Yes | No

    Default

    Hello Matthew

    you can't to use a USART module on a 16f627 because this PIC has not this function.

  3. #3
    's Avatar
    Guest


    Did you find this post helpful? Yes | No

    Default

    1000 apologies it's false

  4. #4
    electronicsuk's Avatar
    electronicsuk Guest


    Did you find this post helpful? Yes | No

    Default

    Well the good news is that I have the USART working now. Trouble is, I wanted to use it because it has an input buffer. I assumed it would buffer the two bytes it receives, allowing me to read them later on in the program. The HSERIN command seems to wait until it receives the data, or you can specify a timeout. Surely this is pretty much the same as using the SERIN command? My program has to continue working at the same time as receiving serial data. So, how can I do this? It doesn't look like PICBASIC will allow it. I tried specifying a timeout, but the timeout has to be very short and I still don't receive any serial data. Doesn't this really defeat the purpose of the buffer?

    Perhaps i'm using the command wrong. Any help or advice is much appreciated. Perhaps I need to program this bit in ASM, trouble is I can't program in ASM.

    Best regards,
    Matthew

  5. #5
    sherm's Avatar
    sherm Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Matthew,

    Among the many consecutive projects I have running is a desire to make my own serial LCD using pbp. I have code for an asm version but that defeats the learning process in this particular case. Anyhow, in everything I've researched to date it would appear that the only truly reliable way around this problem is to use interupts. That way you are just buffering a single incoming byte, doing other stuff with your code while waiting for the next byte and so on. That will also allow you to parse those bytes once you have them while waiting for the next lot of data to arrive. I don't have any solid code for this at this time, but it is most likely the same path that you will have to take. While I haven't begun experimenting with the pbp interupt instruction set yet, from what I have read code becomes large and has a lot of overhead as a result. Sadly, asm routines may be a better answer even if intermingled into your .bas code with ASM...ENDASM

    Good coding,

    Sherm

  6. #6
    electronicsuk's Avatar
    electronicsuk Guest


    Did you find this post helpful? Yes | No

    Default

    Well thanks for the advice Sherm. Still, if anyone else has ideas they would be much appreciated.

    Best regards,
    Matthew

  7. #7
    's Avatar
    Guest


    Did you find this post helpful? Yes | No

    Default hrsin

    hello all,

    the interupt thing isn't that easy .

    but you can specify a very short timeout , if it has 1 char in buffer it will receive that , otherwise it will timeout.

    this works for me.

    grtx , arnold

  8. #8
    Join Date
    Dec 2003
    Location
    San Diego
    Posts
    35


    Did you find this post helpful? Yes | No

    Red face USART receive interupt

    I also am trying to get the example hserin code to work.
    It does not seem to be correct.. (the one that uses PIR1A.5 or so)
    I need a tight loop to collect bursts of serial string data @ 9600 and would like to know when the first byte enters the two byte buffer.

    I was thinking of monitoring the actial input pin that is connected to the usart.... (lookin for a start bit)... that would give me fair warning that something was entering the usart.... then pop over to the hserin and wait for the byte to show. kind of a poor mans data based interupt
    Has anyone done this ??

    That would give me time to get back and service the usart before it overflows. I could care less knowing when it is full because it's too late.

    I now use hserin with a 2 ms timeout and it works OK for now.
    Is there a good book out there that gives examples of interupt use with the usart?

    876 and 877 here....

    tcbcats

  9. #9
    electronicsuk's Avatar
    electronicsuk Guest


    Did you find this post helpful? Yes | No

    Default

    After some more experimentation, I've found it best to do away with the HSERIN command. Just keep an eye out for the receive flag. When it gets set, read in the RCREG register directly to a byte sized variable. If the flag is still set then read the register again for your second byte. The flag should be automatically cleared.

    Matthew

Similar Threads

  1. timeout of Hserin, goto, gosub or both?
    By flipper_md in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2009, 18:43
  2. Instant Interrupts and HSERIN
    By Rob in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 31st January 2009, 05:13
  3. HSERIN problem
    By eggman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th October 2007, 21:31
  4. 16F877a Interupt driven Hserin
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd November 2006, 00:38
  5. Hserin
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th November 2004, 15:42

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