Hot!USART interrupt

Author
Neraildes
Starting Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2017/10/11 07:13:25
  • Location: 0
  • Status: offline
2017/10/13 03:46:03 (permalink)
0

USART interrupt

Hi,
Can anyone tell me if the MPLAB X IDE v3.65 IDE does interrupt simulation for USART?
Please post a code of how I should call the USART interrupt for microcontrollers without interrupt priority (PIC16F876A).
 
thank you very much
#1

4 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 6257
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: USART interrupt 2017/10/13 04:18:47 (permalink)
    +2 (2)
    Yes, the simulator should trigger an interrupt if you inject data to the RCREG register, and have receive interrupts enabled.
    You did not mention if you are working in C or assembler.
    (Or why you are using such an ancient PIC. There are much better, cheaper, easier to work with PIC16F devices now.)
     
     
    #2
    Neraildes
    Starting Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: USART interrupt 2017/10/13 04:37:31 (permalink)
    0
    Hi,
     
    I´m working in C. The compiller is xc8-v1.42.
    Please post a code of how I should call the USART interrupt.
     
    thank you very much
    #3
    katela
    Super Member
    • Total Posts : 550
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: USART interrupt 2017/10/13 11:25:09 (permalink)
    +2 (2)
    In your Main code:
    1. Turn ON interrupt on USART
    2. Clear Interrupt Flag
    3. Enable Peripheral Interrupts
    4. Enable Global Interrupts
    In your Interrupt Routine:
    1. Check for received interrupt flag bit
    2. Do what you need to do

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    Youtube Tutorials: http://www.youtube.com/user/StudentCompanionSA/videos
    #4
    JorgeF
    Super Member
    • Total Posts : 2788
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: Barcelona/Spain/Europe/Third rock from the Sun
    • Status: offline
    Re: USART interrupt 2017/10/13 11:54:30 (permalink)
    +3 (3)
    Hi
    Neraildes
    Please post a code of how I should call the USART interrupt.

    As you might have seen in Katela's post, you don't call the interrupt service routine (ISR), the hardware does it.

    All you have to do is to prepare the hardware for it, like already explained by Katela.
     
    As this is a PIC 16 device you have one single interrupt vector, so the code in the ISR must verify which interrupt source did invoke it and act acordingly.
     
     
    BTW: I would swap the order of steps 1 and 2 in the sequence suggested by Katela. Just in case the EUSART receive interrupt flag was already set before you start preparing for it.
     
     
    HIH
     
    Best regards
    Jorge
     
     
    post edited by JorgeF - 2017/10/13 11:59:03
    #5
    Jump to:
    © 2017 APG vNext Commercial Version 4.5