The eventual issue was that the next command after sleep is never executed, despite what all the docs say. The wake caused random jumps to various parts of the code and I had to add a service routine.