How to debug crashing application?

I’m trying to use an arduino library and it seems to be crashing the Core, but I have no idea how to determine where and/or what the problem is. I’m using local development and make compiles the app without error. I also tried the Cloud IDE with the same results.

I have a bare minimum application uploaded to github, I’m hoping someone might be able to point me in the area that would cause the Core to crash. Or even an idea of how to debug a crashing core once it’s running.

The Core runs just fine if I comment out the radio.powerOn() on line 16, but as soon as I try to power on the Si4703 chip, the core crashes.

What I find odd is that this same library was working perfectly fine for me for a few weeks. Just tonight I did a git pull to update my local core-firmware, core-common-lib, and core-communication-lib folders.

I’m wondering if there’s been some change to the I2C Wire library that may be affecting the functionality of this Arduino library.

Any help is much much much appreciated.

Is it possible that you missed this one, or forgot to update your sketch before reflashing it?

crstffr, I don’t readily see any problems in your code and I noticed you seem you have set the correct, non-shifted I2C 7-bit address for the device. However, as part of the powerOn() procedure, readRegisters() is called. It contains a blocking while() loop:

void Si4703::readRegisters(){

  //Si4703 begins reading from register upper register of 0x0A and reads to 0x0F, then loops to 0x00.
  Wire.requestFrom(SI4703, 32); //We want to read the entire register set from 0x0A to 0x09 = 32 bytes.

  while(Wire.available() < 32) ; //Wait for 16 words/32 bytes to come back from slave I2C device

The easiest way to debug is using the USB serial output of the Spark. By putting serial.print() lines in the code, you can trace its execution and the value of variables. You should put a serial.print line before and after the while() above to see it hangs at the while(). I have to ask the obvious… do you have 4.7K ohm pull-ups on the I2C lines?

Thank you both @Moors7 and @peekay123. I’m not a hardware person and I don’t understand I2C programming or even what a 7-bit address is. That Si4703 library is just something I found on Github.

@peekay123, do you know any reason why that loop would have functioned previously but now it never exits? And if that loop never exits, how would I correct it to work properly?

Also, no I do not have pull-up resistors on the lines. Are they necessary?

crstffr, you the pull-ups are needed because the Spark I2C does not pull the lines up like an arduino. If I can assume you are using a sparkfun breakout, then those pull-up are already on board. However, make sure the length of wires used for the I2C are kept to a minimum length. Can you please confirm which si4703 module you are using and the original library location?

Many things have changed in the past few weeks but besides the 7-bit addressing issue and the pull-ups, there is nothing new with I2C. Have you changed any in your hardware like wire length, placement, power supply or anything like that?

I’m still trying to figure out the serial debugging. I have never been able to get it working very well at all, but I am trying.

Here is the board. Here is the library.

Yes, I recently re-routed my breadboard - and in doing so I made the whole thing more compact - wires are shorter now. I will triple check everything right now.

Thanks @peekay123, working with the spark core for the past few months has been simultaneously fun and absolutely maddening. Help like this makes it possible to keep going. :smile:

I don’t know what it was, but I moved some things around and now it works again. It must have been a wiring issue after all. Thanks a ton for your help.

So typical crstffr… gremlins in the works! Glad it’s working. If you can, share your ideas and projects with the community. :smile:

If you are building localy use DEBUG_BUILD=y and add

void debug_output_(const char *p)
      static boolean once = false;
     if (!once)
         once = true;
         Serial1.begin(115200); // You can choose where the debug goes 


in you application.cpp.

Then add all the DEBUG("connection closed %d 0x%04x",retValue, address); you want.

You get to leave em all in and in a release build they are automagically removed!

Happy debugging!

If you have an JTAG add USE_SWO_JTAG=y too!

See for details