• AVR Freaks

Hot!Can interrupts be used with USART?

Author
gred
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/12/08 03:50:24
  • Location: 0
  • Status: offline
2020/01/26 03:50:29 (permalink)
0

Can interrupts be used with USART?

I have 2 functions in while (1) loop. one for continuously receiving data from the bluetooth module and the other for keypad scanning. The data received from the respective functions are stored in 2 different variables, one for the keypad and the other for bluetooth. I have two if statements to receive data from. One for keypad and the other for bluetooth. Upon entering the correct password, the led lights up. My problem now is that i can't use the keypad when i include the blutooth function inside. Is this due to a conflict in priority of the if statements? Because one is checking the data_in from bluetooth an the other is checking for keypressed from keypad. Should i set up an interrupt and prioritize?
#1

3 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1776
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: Can interrupts be used with USART? 2020/01/26 04:22:38 (permalink)
    +1 (1)
    gred
    Is this due to a conflict in priority of the if statements?

     
    How on earth do you expect an answer to that without showing your code?
     
    In answer to the title thread "Can interrupts be used with USART?"

    Yes, they can.
    #2
    ric
    Super Member
    • Total Posts : 25550
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Can interrupts be used with USART? 2020/01/26 04:30:08 (permalink)
    +2 (2)
    gred
    ... Is this due to a conflict in priority of the if statements?

    It's most likely due to badly written code, hogging the CPU rather than working cooperatively.
     
    n.b. keypad scanning would be better done inside a timer interrupt, which gives you nicely consistent timing.
    Just doing it as part of your main loop means the scan timing varies with what code you run.
     
    post edited by ric - 2020/01/26 04:46:15

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Mysil
    Super Member
    • Total Posts : 3632
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Can interrupts be used with USART? 2020/01/26 06:36:09 (permalink)
    +2 (2)
    Yes,
    USART communication may well be handled by interrupts.
     
    But you do not tell what PIC device is beeing used, not even which family !!!
    The thread is however in: 8-Bit Microcontrollers Forum ...
    so unless you are using a obsolete device, then
    MPLAB Code Configurator (MCC) can show you how it can be done.
     
    Especially EUSART receiving can benefit from interrupt handling. 
     
    And as suggested in message above, keypad scanning may preferably be done in a timer interrupt.
     
        Mysil
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5