I have a product that needs to act as an I2C slave and wake up from sleep, I'm using a SAMD11. I've spent a long time trying to track down the problem, which only happens sometimes. I've instrumented my code to drive GPIO to show what is happening.
This is what happens when it works. For testing I have added a resistor in series in the sda and sdc so the slave can pull the line lower than the master and have included analog captures. For reference the production product has better capacitance/resistance than the debug setup.
- The samd11 starts in 'standby sleep mode' it is set to wake on a matching I2C address.
- A matching address occurs, and on the 9th low transition the samd11 holds the SCL line (shown on channel 1) to clock stretch.
- The samd11 enters the interrupt handler, which sends an ack on the I2C and a variable is set to signals to the main loop to not sleep again until data is processed. The rest of the I2C transactions complete and after recieving a STOP, the device enters sleep again.
This is all correct behaviour. However, apparently randomly sometimes the samd11 doesn't wake up as shown here:
Here, it can be seen that that the samd11 doesn't hold the SCL, nor is the interrupt handler entered. Even more odd, about 10ms later the chip hard faults.
As can be seen from an overview, the faults are sporadic.
To trace what was going on, I tried to make sure that the first instruction in the interrupt handler and the first instruction after the WFI instruction both are to drive the GPIO line to signal in the traces. I've double checked the driver code (using both ASF and then writing my own interrupt routines) and can see no problem. In addition, the samd11 behaves correctly when the same code runs but only IDLE2 sleep rather than STANDBY is used.
This issue has taken a lot of time, but I'm beginning to think it's a bug in the hardware related to wake from STANDBY.
I've checked the forum and can't see any other solutions, though other people report problems when coming out of sleep and I wonder if they're related -- e.g. https://community.atmel.com/foru..., https://community.atmel.com/foru...
In my I2C slave example we can see the events leading up to the chip waking up, where a timer is internal. From the behaviour I observe I'm struggling to think how it can be anything other than a hardware bug -- no code appears to get run that could fail, yet a hardfault occurs.
Obviously I'm keen to try and get this sorted especially if it sheds any light on other similar problems with wake -- thanks in advance for any other suggestions.