# SparkIntervalTimer

**URL:** <https://community.particle.io/t/sparkintervaltimer/14515>\
**Category:** Troubleshooting\
**Created:** [August 19, 2015, 1:52pm UTC](https://community.particle.io/t/sparkintervaltimer/14515 "2015-08-19T13:52:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammedmidhat](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mohammedmidhat](https://community.particle.io/u/mohammedmidhat)\
**Post date:** [August 19, 2015, 1:52pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/1 "2015-08-19T13:52:09Z")

</div>

Hi,

I’m trying to make timer interrupts by using the SparkIntervalTimer library found on the cloud. My code looks like this:

```auto
// This #include statement was automatically added by the Particle IDE.
#include "SparkIntervalTimer/SparkIntervalTimer.h"

IntervalTimer myTimer;

void blink(void);

void setup() {
    myTimer.begin(blink, 5000, hmSec);
}

void blink(void) {
    Spark.publish("hello", "5");
}

void loop() {
    
}

And I am getting these compilation errors:

SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:178:10: warning: statement has no effect [-Wunused-value]
    scale == uSec; // Default to microseconds
          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::interrupt_SIT(action)':
SparkIntervalTimer/SparkIntervalTimer.cpp:261:15: warning: variable 'TIMx' set but not used [-Wunused-but-set-variable]
  TIM_TypeDef* TIMx;
               ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:305:26: warning: unused variable 'timerInitStructure' [-Wunused-variable]
  TIM_TimeBaseInitTypeDef timerInitStructure;
                          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:191:43: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);
                                           ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:247:18: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_DeInit(TIMx);
                  ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:336:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIMx->PSC = prescaler;
                       ^
../../../build/target/user/platform-6/libuser.a(particle-ktbox.o): In function `__static_initialization_and_destruction_0':
particle-ktbox.cpp:4: undefined reference to `SystemCoreClock'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM2_Interrupt_Handler'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM3_Interrupt_Handler'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM4_Interrupt_Handler'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM2_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:37: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:39: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM3_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:47: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:49: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM4_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:57: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:59: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `IntervalTimer::start_SIT(unsigned short, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:163: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:153: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:158: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:189: undefined reference to `TIM_TimeBaseInit'
SparkIntervalTimer/SparkIntervalTimer.cpp:190: undefined reference to `TIM_Cmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:191: undefined reference to `TIM_ITConfig'
SparkIntervalTimer/SparkIntervalTimer.cpp:200: undefined reference to `NVIC_Init'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:240: undefined reference to `TIM_Cmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:244: undefined reference to `NVIC_Init'
SparkIntervalTimer/SparkIntervalTimer.cpp:247: undefined reference to `TIM_DeInit'
collect2: error: ld returned 1 exit status
make: *** [b6cc983af97e12c7345eaae9484624c7abc8ee1af7a119aba287c76d0932.elf] Error 1
Error: Could not compile. Please review your code.

If I try this line instead of my old line: myTimer.begin(blink(), 5000, hmSec);

I get this error message:
 
particle-ktbox.cpp: In function 'void setup()':
particle-ktbox.cpp:11:39: error: invalid use of void expression
 void blink(void);
                                       ^

make[1]: *** [../build/target/user/platform-6particle-ktbox.o] Error 1
make: *** [user] Error 2

```

I will appreciate any help on this.

Best Regards,  
Mohammed

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [August 19, 2015, 2:51pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/2 "2015-08-19T14:51:43Z")

</div>

@mohammedmidhat, the current library is not compatible with the Photon and as soon as the new firmware version is released (0.4.4rc?), I will be releasing a new version of SparkIntervalTimer. 😄

---

<div class="post-metadata">

**Author:** ![mohammedmidhat](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mohammedmidhat](https://community.particle.io/u/mohammedmidhat)\
**Post date:** [August 19, 2015, 3:08pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/3 "2015-08-19T15:08:49Z")

</div>

Thank you @peekay123, do you think of any other solution for making a timer with the Photon for now?

Best,  
Mohammed

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [August 19, 2015, 3:26pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/4 "2015-08-19T15:26:10Z")

</div>

@mohammedmidhat, the new firmware will be released this week!

---

<div class="post-metadata">

**Author:** ![mohammedmidhat](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mohammedmidhat](https://community.particle.io/u/mohammedmidhat)\
**Post date:** [August 19, 2015, 4:23pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/5 "2015-08-19T16:23:26Z")

</div>

Thank you very much @peekay123.

---

<div class="post-metadata">

**Author:** ![guru\_florida](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/guru_florida/32/178_2.png) [@guru\_florida](https://community.particle.io/u/guru_florida)\
**Post date:** [September 3, 2015, 5:44pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/6 "2015-09-03T17:44:33Z")

</div>

Hi @peekay123, I noticed in your last commit Aug 21 that you added Photon support. I am still getting linking errors on the TIMx symbols…are your photon support changes working?

Thanks,  
Colin

```
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::interrupt_SIT(action)':
SparkIntervalTimer/SparkIntervalTimer.cpp:261:15: warning: variable 'TIMx' set but not used [-Wunused-but-set-variable]
  TIM_TypeDef* TIMx;
               ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:305:26: warning: unused variable 'timerInitStructure' [-Wunused-variable]
  TIM_TimeBaseInitTypeDef timerInitStructure;
                          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:191:43: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);
                                           ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:247:18: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_DeInit(TIMx);
                  ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:336:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIMx->PSC = prescaler;
                       ^
../../../build/target/user/platform-6/libuser.a(treadmill.o): In function `__static_initialization_and_destruction_0':
treadmill.cpp:174: undefined reference to `Wiring_TIM2_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM3_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM4_Interrupt_Handler'
collect2: error: ld returned 1 exit status
make: *** [b73d42f72c0d304b288f92787719593929076cf4dbb8c6f1a379c3b5e6f2.elf] Error 1
```

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [September 3, 2015, 6:51pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/7 "2015-09-03T18:51:17Z")

</div>

@guru_florida,

The Photon compatible SparkIntervalTimer library is now available in the web IDE and [here](https://github.com/pkourany/SparkIntervalTimer) on my githut. Sorry for the delay!!

---

<div class="post-metadata">

**Author:** ![guru\_florida](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/guru_florida/32/178_2.png) [@guru\_florida](https://community.particle.io/u/guru_florida)\
**Post date:** [September 3, 2015, 8:42pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/8 "2015-09-03T20:42:35Z")

</div>

Thanks @peekay123, I reimported the project in the web IDE, and I’ve confirmed I have the latest code with the scale == uSec fix. I’ve even forked your project and tried importing that but I get the same linking errors. Any ideas?

```
treadmill.cpp:174: undefined reference to `Wiring_TIM2_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM3_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM4_Interrupt_Handler'

```

I also get all the TIMx may be uninitialized as well.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [September 3, 2015, 11:21pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/9 "2015-09-03T23:21:43Z")

</div>

@guru_florida, are you compiling for a Core or Photon target?

---

<div class="post-metadata">

**Author:** ![guru\_florida](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/guru_florida/32/178_2.png) [@guru\_florida](https://community.particle.io/u/guru_florida)\
**Post date:** [September 4, 2015, 4:21am UTC](https://community.particle.io/t/sparkintervaltimer/14515/10 "2015-09-04T04:21:50Z")

</div>

Photon

---

<div class="post-metadata">

**Author:** ![Fabien](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/fabien/32/8139_2.png) [@Fabien](https://community.particle.io/u/Fabien)\
**Post date:** [September 4, 2015, 7:30am UTC](https://community.particle.io/t/sparkintervaltimer/14515/11 "2015-09-04T07:30:05Z")

</div>

Make sure you use the latest version from the web IDE. By default it shown me the 1.2.0. After refreshing the list, I can see the 1.3.2

[edit] I have the same error as you. However I am not sure the compiler is using the version 1.3.2. How to check this??

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [September 4, 2015, 11:30am UTC](https://community.particle.io/t/sparkintervaltimer/14515/12 "2015-09-04T11:30:50Z")

</div>

@guru_florida, @Fabien, it seems something is odd with the IDE. When I load the library this morning, it is showing up a the old version. When I reload the new version, it says that version already exists but then, the new version show up!! When I load it and compile, it gives an error on a line which should compile. If I delete the line, save, reinsert the line save and compile again, it works! I’ll ping the folks at Particle to see what gives. In the meantime, I HIGHLY recommend using the Particle DEV and downloading the code directly from github. 🙂

---

<div class="post-metadata">

**Author:** ![guru\_florida](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/guru_florida/32/178_2.png) [@guru\_florida](https://community.particle.io/u/guru_florida)\
**Post date:** [September 4, 2015, 1:09pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/13 "2015-09-04T13:09:41Z")

</div>

Thanks @peekay123! The IDE has been a crap-shoot for me overall. So buggy. I keep trying it thinking, “well they’ll have it all sorted out by now…” 2 years later and…nope. ☹

I have local dev for core already, I’ll move to that for Photon as well. Thanks for your support! Great library, no surprise it’s about 5th from the top.

---

<div class="post-metadata">

**Author:** ![McTristan](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@McTristan](https://community.particle.io/u/McTristan)\
**Post date:** [September 11, 2015, 9:58pm UTC](https://community.particle.io/t/sparkintervaltimer/14515/14 "2015-09-11T21:58:26Z")

</div>

@peekay123 excellent news about the new library, haven’t had enough time and i’m just checking… Great work!
