Compiler Error when using radio and interrupt libraries

Hey guys,

I won't get into all the nitty gritty details unless required, but I'm running a LoRa radio library and a GPS module. The GPS module requires that I read the gps output ever 1ms. To do this they recommend using an interrupt on the M0.

From a bit of digging, interrupts seem much harder on the M0 than on more standard arduino systems. Luckily I found a library that a guy wrote that simplifies everything:

http://www.avdweb.nl/arduino/libraries/samd21-timer.html

Using his library, I was able to make a working interrupt.

I took that exact interrupt and copied it into my LoRa radio code and I get a compiler error. I think the libraries are conflicting.

Here is a simpler example. Just by loading the radio code and SAMDtimer libraries, I get a compiler error.

#include <SPI.h>
#include <RH_RF69.h>
#include <Arduino.h>
#include <avdweb_SAMDtimer.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

The compiler error is as follows:

libraries\Adafruit_ASFcore\tc_interrupt.c.o: In function `TC3_Handler':

C:\Users\jaleemhu\Documents\Arduino\libraries\Adafruit_ASFcore/tc_interrupt.c:140: multiple definition of `TC3_Handler'

libraries\RadioHead\RH_ASK.cpp.o:C:\Users\jaleemhu\Documents\Arduino\libraries\RadioHead/RH_ASK.cpp:600: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Adafruit Feather M0.

Now to my question, is there a way I could modify the interrupt library so I can remove this conflict? I think it's the only thing keeping me from finishing my project and this is a bit over my head.

Thanks guys!

I think the libraries are conflicting.

Well of course they are, since you didn't even bother to rename the handler.

Now, of course, we do not see any links to the libraries you are using, so we can only guess at what TC3_Handler() is going to do.

However, it seems likely that you will not be able to use both libraries together, since they apparently both need the same resource, and there is only one of whatever it is they need.

Radio Library: https://cdn-learn.adafruit.com/assets/assets/000/035/106/original/RadioHead-1.62.zip?1472068723

SAMD Timer library: GitHub - avandalen/avdweb_SAMDtimer: SAMD21 Timer library for the SAM15x15 and Arduino Zero

If it's a timer they need, perhaps changing the library to use a different timer?

The conflict seems to be here for Adafruit_ASFcore

/**
 * \internal ISR handler for TC
 *
 * Auto-generate a set of interrupt handlers for each TC in the device.
 */
#define _TC_INTERRUPT_HANDLER(n, m) \
 void TC##n##_Handler(void) \
 { \
 _tc_interrupt_handler(m); \
 }

#if (SAML21E) || (SAML21G)
 _TC_INTERRUPT_HANDLER(0,0)
 _TC_INTERRUPT_HANDLER(1,1)
 _TC_INTERRUPT_HANDLER(4,2)
#else
 MRECURSION(TC_INST_NUM, _TC_INTERRUPT_HANDLER, TC_INST_MAX_ID)
#endif

Specifically it's pointing at the MRECURSION line

and conflicts with:

#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY) 
void TIMER1_COMPA_vect(void)
{
    thisASKDriver->handleTimerInterrupt();
}

#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(ARDUINO_ARCH_SAMD)
// Arduino Zero
void TC3_Handler()
{
    // The type cast must fit with the selected timer mode
    TcCount16* TC = (TcCount16*)RH_ASK_ZERO_TIMER; // get timer struct
    TC->INTFLAG.bit.MC0 = 1;
    thisASKDriver->handleTimerInterrupt();
}

Specifically the function TC3_Handler.

Doubt that helps, but it's some more details.

I would be very surprised if you need to use interrupts at all. In Arduino terms 1 millisec is a long time and it should be doable with polling using micros() to manage the timing.

In any case, I can't see the need to read a GPS every millisec - your position won't change that quickly. i suspect once every 10 seconds would be sufficient - or maybe once per minute.

Be careful not to waste more time trying to figure out a library than you would need to write the same functionality without the library.

...R

Hello, I ran into the same problem interfacing the Adafruit_NeoPixel_ZeroDMA and the Radiohead library on a Feather M0... after a little bit of trial and error, I found this seemingly reasonable solution.

Comment out the 7 lines of void TC3_Handler() to eliminate the multiple definition error

This works for my application, but I'm interested to know what (if any) the consequence of this modification is!?

Good luck.

This works for my application, but I'm interested to know what (if any) the consequence of this modification is!?

You can wonder til the cows come home, or you can post a link to the library that you modified, and get help understanding what you did.