# Compilation of Core code for Photon Gives Errors

**URL:** <https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195>\
**Category:** Troubleshooting\
**Created:** [May 30, 2015, 6:42pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195 "2015-05-30T18:42:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 30, 2015, 6:42pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/1 "2015-05-30T18:42:50Z")

</div>

I have firmware that compiles and runs just fine on three Cores. I just got my Photon and tried to compile and upload the identical code. First, I got two compile errors for the Photon what do not give compile errors when I compile the identical source code file for the Core. Offending lines are:  
Spark.syncTime();  
Wire.setSpeed(COCK\_SPEED\_100KHZ);

I commented out these two lines and the code compiles for both Photon and Core. I uploaded this code to both a Core and a Photon and it uploaded fine. It runs fine on the Core. On the Photon, it seems to run fine (at least by blinking LEDs) but my Javascript that reads calls Spark.function() does not seem to be executing properly: returns “errornull” (at least that’s what Javascript displays).

This all seems to indicate that there must be some #include that is needed for compiling Core firmware on a Photon. Please help me to understand what I need to do to port 100% solid working Core code over to Photon!

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [May 30, 2015, 6:48pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/2 "2015-05-30T18:48:32Z")

</div>

Could you post the complete code so we can have a look and see what the issues might be?

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [May 30, 2015, 7:13pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/3 "2015-05-30T19:13:26Z")

</div>

`Spark.syncTime()` is a known issue and will be fixed in the next release (in ca. 10 days time.)

The time is synced to the cloud at the start of each connection, so typically the syncTime() call is not always necessary.

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 30, 2015, 8:47pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/4 "2015-05-30T20:47:47Z")

</div>

@Moors7: Code is posted at: [https://github.com/JimBob2015/Saratoga\_SIS](https://github.com/JimBob2015/Saratoga_SIS). File is SaratogaSIS08.

I am using the WebIDE. After downloading the new app to my smartphone and capturing my new Photon, I logged into my Particle development account and selected the Photon (it was there, along with my two earlier Cores). I successfully compiled, uploaded, and executed blink. I then selected SaratogaSIS08 firmware that was previously saved and re-compiled it for the selected device (the Photon). This is where I got the two compile errors listed above (plus a bunch of warnings that have always been there and were never a problem, but p.s. I thought that these extraneous warnings would now be surpressed). On the same web IDE, if I select one of my Cores and compile the identical file, it compiles OK.

As I mentioned previously, this code has been running fine on 3 Cores (2 mine and one owned by my co-developer) for many weeks now. After commenting out these two offending lines, the revised code compiles for both Core and Photon. The revised code uploads to Core OK and runs OK. The revised code uploads to Photon OK but does not run OK. Specifically, I can use the REST interface (via Javascript) and read out the Spark.variable() exposed variables OK. But when I run a function exposed by Spark.function() that causes an update to an exposed variable, my Javascipt returns “errornull” from the Photon but runs just fine on the Core. I also suspect that the I2C is not running properly on the Photon with the revised code (probably because of the commented out clock speed line).

Note that this program requires the Core/Photon to be in a circuit that uses the I2C bus (to write config data to an I2C eeprom) and has 2 digital inputs from 2 RF receivers that are on pins D3 and D4 (uses interrupts).

@mdma: thanks for the headsup about bug fix on Spark.syncTime(). However, there is more going on here. It is almost like the web IDE doesn’t #include the right core library files for Photon when the same code has previously been compiled for Core. Note, however, that I did recompile after selecting the Photon from my device list.

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 31, 2015, 1:00am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/5 "2015-05-31T01:00:18Z")

</div>

An update: I got my code working on the Photon by commenting out the lines:  
Spark.syncTime();  
Wire.setSpeed(CLOCK\_SPEED\_100KHZ);

I understand the Spark.syncTime() is a known bug and will be fixed. Wire.setSpeed(CLOCK\_SPEED\_100KHZ); may not be needed as it is (presumably) the default, but failure to compile this specified function is a bug and it should be fixed.

My other problem was that two Spark.variable() names were \> 12 characters. This is not a problem when compiling for the Core because the name is simply truncated to 12 characters. For some reason, it is a problem when compiling for Photon, as the variables were not exposed to the cloud. I truncated them to the legal 12 chars in my firmware and I am pleased to report that the code is working on Core and on Photon. I don’t count this latter difference as a bug because I had not followed the rules, but it is a difference between how Core and Photon work and I am describing it here in case other people have this same issue.

Particle folks: please do fix the 2 compile issues noted above and kindly let us knoe when they are fixed.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [May 31, 2015, 1:12am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/6 "2015-05-31T01:12:15Z")

</div>

@BobG,

you can always file an issue here: [https://github.com/spark/firmware](https://github.com/spark/firmware)

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 31, 2015, 1:25am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/7 "2015-05-31T01:25:24Z")

</div>

@kennethlimcp: it seems that I need the GitHub password for the Spark account on GitHub to do this. Since i don’t have the passowrd, would you be so kind as to log these two issues for me?  
Thanks.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [May 31, 2015, 1:27am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/8 "2015-05-31T01:27:25Z")

</div>

That’s not true. You can use your own github account and open an issue here: [https://github.com/spark/firmware/issues/new](https://github.com/spark/firmware/issues/new)

I’m help to do so if you still face any problem opening one 😉

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 31, 2015, 4:12am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/9 "2015-05-31T04:12:29Z")

</div>

Thanks. I logged the issues.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [May 31, 2015, 11:29am UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/10 "2015-05-31T11:29:04Z")

</div>

As a workaround for the Wire error above, could you please add

```cpp

#include "i2c_hal.h"

```

to your program. that will pull in the needed defines for the clock speed. This will be fixed in the next release.

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [May 31, 2015, 5:46pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/11 "2015-05-31T17:46:33Z")

</div>

@mdma: thanks. I’ll try this tomorrow and I’ll only report back if there is a problem. I appreciate the quick turnaround on the fix to these compile issues.

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [June 1, 2015, 5:16pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/12 "2015-06-01T17:16:29Z")

</div>

@mdma: I added the #include and it does, indeed, compile correctly for the Photon. However, the same file gives compile errors when compiling for Core. Since I have 2 Cores and 1 Photon, I need a single version of code that will compile for both. So there needs to be some sort of #ifdef to add or not add the #include based upon the target device type. Hopefully, this will be OK in the released version. I can wait for the new release (this is the default anyway and the I2C bus seems to work fine with the setSpeed line commented out) but I wanted to make sure that the fixes in new release will compile correctly for both Photon and Core.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [June 1, 2015, 6:07pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/13 "2015-06-01T18:07:19Z")

</div>

Ah ok Didn’t realize you were targeting both. The HAL is part of the new firmware, which defines PRODUCT\_ID, so we can detect that with:

```auto
#ifdef PLATFORM_ID
#include "i2c_hal.h"
#endif

```

---

<div class="post-metadata">

**Author:** ![BobG](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@BobG](https://community.particle.io/u/BobG)\
**Post date:** [June 1, 2015, 6:24pm UTC](https://community.particle.io/t/compilation-of-core-code-for-photon-gives-errors/12195/14 "2015-06-01T18:24:13Z")

</div>

@mdma: thanks. Kindly make sure that this is included in the next release.
