PIC Basic PRO 16F877 USART Interrupt TX


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

    Angry PIC Basic PRO 16F877 USART Interrupt TX

    Hi
    I have started a new thread, can anybody tell me why the Code Below will not Output Serial under TX Interrupts.

    Regards Henry
    **********

    define HSER_TXSTA 20h
    define HSER_BAUD 9600
    DEFINE HSER_SPBRG 25

    StrOut VAR BYTE[20]
    I VAR WORD
    ENABLE
    strout(0) = "H"
    strout(1) = "e"
    strout(2) = "n"
    strout(3) = "r"
    strout(4) = "y"
    strout(5) = 13
    strout(6) = 10
    strout(7) = 0
    I = 0

    ON INTERRUPT GOTO INTERRUPT_HANDLER
    INTCON = %10010000
    'PIE1.5 = 1 ' enable interrupt on usart receive
    PIE1.4 = 1 ' enable interrupt on usart transmit
    ENABLE INTERRUPT

    HSerout [strout(0)] 'Out Put 1 Character

    Main_Loop:
    NOP
    NOP
    NOP
    GOTO Main_Loop
    END

    SerialOut:
    For i = 0 TO 20
    IF strout(i) = 0 Then
    i = 20
    Else
    HSerout [strout(i)]
    EndIF
    Next i
    Return


    DISABLE INTERRUPT
    INTERRUPT_HANDLER:
    GOSUB SerialOut
    'PIR1.5 = 0 'Receive
    PIR1.4 = 0 'Transmit
    RESUME
    ENABLE INTERRUPT

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    BigH, For starters I would put the "serialout" routine inside of the DISABLE/ENABLE constructs of the interrupt routine. It is not a very good practice to call a subroutine from inside of an interrupt.

    Dave Purola,
    N8NTA

  3. #3
    BigH's Avatar
    BigH Guest

    Default No Change Still See "H" Only

    Hi Dave
    Thanks for your Reply, but made no difference in Execution Still Refuses to Interrupt. The calling of Sub Routine has a Time Penalty which I guess is why its consider a No No
    Regards Henry

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

    Default

    What do you need to do exactly? Maybe i'm dumb but i don't see what you want to do with that.
    Steve

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

  5. #5
    BigH's Avatar
    BigH Guest

    Default Test Program

    Hi
    Its suposed to be a very simple test program to get a full understand of Serial USART Output using Interrupts and how to manage the Data Flow. It will be used in a serious piece of code where Both Serial USART Input and Output are manage by Interrupts Only while processing and Controlling the Data Flow to maximise throughput so no Data is lost in Peak Input Conditions.
    Regards Henry

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

    Default

    Oh Boy. Where to start. I guess from the beginning.

    Since there isn't an OSC definition, I assume you're running at 4Mhz. And, with 4 Mhz, and BRGH (TXSTA.2) set to 0. The error rate for 9600 baud is 7%. That's really high. If you use HSER_TXSTA 24, which sets BRGH to 1, the error rate goes to 0.16%.

    But then you manually set SPBRG to 25, which would be 2400 baud at 4mhz, so the 9600 gets discarded.

    INTCON = %10010000 Along with turning Global interrups on, also enables the External Interrupt INT. But the rest of the program doesn't use INT.

    'PIE1.5 = 1 ' enable interrupt on usart receive
    This line is commented out, so the RX interrupt never gets enabled.

    PIE1.4 = 1 ' enable interrupt on usart transmit
    You cannot use Transmit interrupts with HSEROUT, they are not compatible.

    Just like the compiler would do, I'll stop there and report [too many errors]

    DT

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

    Default

    Interesting idea. Even if i'm not the best one here in the serial data communication, i feel that you'll need more than 1 PIC for that depending the size of the data you need to send/receive to be really sure you don't miss anything. The internal USART have a buffer of 2 BYTES for incomming data. Maybe enough to stop your serial OUT.

    There's many way to see the solution here. The first that spring to mind now is Sending your data bytes by byte, then check the USART interrupt flag for incomming data each time a byte is sent. Your data to be send may be store in a EEPROM, ARRAY, or, or, or, or...

    Depending what else your project do... 2 PIC can be a solution or not.

    Example of serial interrupt:
    http://www.picbasic.co.uk/forum/show...1&postcount=11
    http://www.picbasic.co.uk/forum/show...42&postcount=2

    Should be enough to start.

    EDIT: Sorry darrel didn't saw your post... the above example should help anyway
    Last edited by mister_e; - 9th January 2006 at 22:56.
    Steve

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

  8. #8
    BigH's Avatar
    BigH Guest

    Smile Thanks

    Hi Guys
    Thanks, with your help I think I can now move in the right direction. I am beginning to think I should have stuck to Delphi and Window instead getting involved with these little Beast's . Thanks Again
    Regards Henry

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

    Default

    i heard it often hurt the first time... good luck.

    Don't be afraid, we all had and still have some problems with them sometimes. There's no problem... only learning opportunities
    Steve

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

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  3. pic basic pro (novice user)
    By f6ggy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd October 2003, 14:29
  4. help pic basic pro
    By f6ggy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2003, 00:55
  5. How to use 93C46 Type EEPROM using PIC Basic PRo
    By in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st April 2003, 04: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