Menu

Arduino Leonardo Interrupts

Help
AichBee
2016-10-30
2016-10-31
  • AichBee

    AichBee - 2016-10-30

    Hi

    Has anyone been able to get interrupts working on an Arduino Leonardo (ATMega32U4)?

    After having success with reading serial data via UART I wanted to use the interrupt to trigger collection of data but was unable to get it to work so thought I would try a simple timer interrupt test but this doesn't seem to work either. The LED lights and stays on. Any ideas? Thanks in advance for any help.

    Code below:

    #chip mega32u4, 16         'This is the  device used by Arduino Leonardo
    
    Dir PORTC.7 Out
    
    Inittimer1  OSC, PS_256
    Starttimer 1
    
    
    On Interrupt Timer1Overflow Call Flash_LED
    
    'turn on onboard LED
    PORTC.7 = 1
    
    Main:
    
    Goto Main
    
    
    Sub Flash_LED
    
     If PORTC.7 = 1 Then
        PORTC.7 = 0
      Else
        PORTC.7 = 1
      End if
    
    End Sub
    
     

    Last edit: AichBee 2016-10-30
  • AichBee

    AichBee - 2016-10-30

    The Compiler Version I have is 0.95.009 2016-08-09 - according to the IDE when compiling code.
    I did try downloading the latest version from the link at http://gcbasic.sourceforge.net/download.html
    but my Avast AV flagged it as containing Malware when I tried to save it.

     
  • Anobium

    Anobium - 2016-10-30

    Look in the Demo folder for interrupt solutions. There are several demos for Atmel. Have a look at those demos.

     
  • AichBee

    AichBee - 2016-10-30

    Yes I've done that and have tried changing a couple for the mega32u4 but still no luck so I guess it might be something to do with the Arduino boot loader code. Thanks anyway - I'll probably ditch the Arduino and go back to PICs which I've used interrupts on without a problem.

     
  • Anobium

    Anobium - 2016-10-31

    We need someone with deep AVR ASM capabilities and the same chip. The approach should work and I cannot test as I do not have that chip.

     

    Last edit: Anobium 2016-10-31
  • AichBee

    AichBee - 2016-10-31

    I assume you meant "we need someone with deep AVR ASM capabilities". I'm sure the approach should work but it doesn't for me on an Arduino Leonardo. However I'm not going to worry about it - I just wondered if anyone else had tried using interrupts on a Leonardo in GCB, or if it was just me. :)

    I was only using the Arduino as it would have been a quick and cheap solution for a MIDI project for a friend who has deep pockets and short arms!

     

    Last edit: AichBee 2016-10-31
  • Anobium

    Anobium - 2016-10-31

    Yes, I did. :-) Edited.

     
  • AichBee

    AichBee - 2016-10-31

    Well problem solved quite by chance!

    I had been using the Arduino Leonardo plugged-in to the computer USB port for programming and whilst running the code on the board.

    When I wasn't using interrupts in my code it always worked fine, but when using code with interrupts it didn't.

    Needing to check if a USB power supply was working, I just happened to plug it into the Arduino (obviously just 5V and Gnd - no data connections) and the Leonardo worked with the code that used interrupts programmed on the chip! Plugged back into the computer USB and it didn't.

    I can only assume that the USB on the Leonardo must use (or just disable the use of) interrupts when a connection is established with the computer.

    It's a bit of a pain as I'll have to keep swapping the USB back and forth from computer to power supply.

    It might perhaps be handy to include this info somewhere in case someone else encounters this?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.