How to tell there is a serial request


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default How to tell there is a serial request

    The voices in my head keep telling me there is something I don't get. How does the PIC know the PC wants to talk? Heres my situation: Using hardware USART, I want to be able to query the PIC from time to time. But the app is time sensitive, so it won't always be a good time to stop and talk to the PC. I would like to be able to see the request from the PC, then respond with a single character that the PC would know means no time to talk right now.

    I can picture this if HSERIN were a command to say start a background type process and when a byte is received an int is generated. then I would jump to the int handler, check a flag to see if its a good time to talk. If not, send the no message back and return. If it is a good time, maybe set a flag to be polled in the main routine.

    The main routine would then see the flag and gosub to the chat routine.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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

    Default

    PIR1.5 is the RCIF (Receive Interrupt Flag).
    If a byte has been received, RCIF will be set.

    The USART has a 2-byte buffer, so the byte received can just sit there until the main program has time to respond.

    You don't really need interrupts for the case you described, as long as the PC only sends 1-byte and waits for the PIC to reply. Then somewhere in your main loop, when the program has time ... check RCIF and respond to the request as needed.
    DT

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default

    Thanks Darrel, so to be clear in my mind, I would do this:
    poll pir1.5 in the main loop
    If set, jump to serial routine

    serial routine:
    check time to talk flag
    If set, HSEROUT an ack and then HSERIN waiting for whatever
    Else HSEROUT no time
    return

    Now how did I get the info in the buffer? Does HSERIN grab whats in the buffer, or look for new received bytes?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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

    Default

    Yes, HSERIN gets it's data from the USART's buffer.

    In the main loop you could ...

    Code:
        IF HaveTime AND RCIF THEN GOSUB Serial
    The PC will wait until the PIC sends it.
    Don't see a reason to tell it there's no time to talk now. But maybe your app needs that.
    DT

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default

    Thanks again Darrel for the explaination.

    The reason to send back a busy byte is for the user. Being me if I try to talk to the card and get nothing, I will likely forget its because my drives are enabled and assume there is something wrong. Then go and spend as much time as possible just to find out all is working as it should.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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