I’m trying to adapt an arduino library for a moisture sensor (https://github.com/Miceuz/i2c-moisture-sensor)
The Photon tells me I have a ‘Usage fault’ when I flash the example but I have no idea how to debug it.
The library I adapted for particle is here : https://github.com/jbgariel/I2CSensorParticle
Thanks a lot !
Hard faults usually have to do with buffer overruns or bad or unassigned pointers.
Oops - Usage Fault is often due to misaligned addresses (non-four-byte boundaries) or zero-div.
A UsageFault is an exception that occurs because of a fault related to instruction execution. This includes:
an undefined instruction
an illegal unaligned access
invalid state on instruction execution
an error on exception return.
The following can cause a UsageFault when the core is configured to report them:
an unaligned address on word and halfword memory access
division by zero.
I’ll have a look at your code if you can narrow down how far your code runs before it happens.
How long is your program running before it happens?
If you want to get into serious debugging you’d need a Programmer Shield or a JTAG/ST-LINK
Thank you for the quick answer, I ordered a Programmer Shield for the photon.
It seems that the code doesn’t run very far as I don’t have any serial.print statement. I’ll add some more tonight.