Surprised about duplicate setup in line 14 in post #7. I think that line should be removed...
Same for the duplicate setup in post #8: line 19 should be removed.
The time killer loops in lines 31..33, 39..41 and 51..53 cause problems because they hog the cpu and nothing else (js-wise) can happen during that time. Wait by burning cycles does not exist / does not work in Espruino... to the contrary, it will break the execution... 'Waiting' has to be done with 'deferred / timed-out resume (w/ setTimeout(...,...); ).
Does the module have a reset command? If so, I would send that before sending the command for turning on the oscillator.
Try something like that - my ugly chained steps with retries on timeouts...
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Surprised about duplicate setup in line 14 in post #7. I think that line should be removed...
Same for the duplicate setup in post #8: line 19 should be removed.
The time killer loops in lines 31..33, 39..41 and 51..53 cause problems because they hog the cpu and nothing else (js-wise) can happen during that time. Wait by burning cycles does not exist / does not work in Espruino... to the contrary, it will break the execution... 'Waiting' has to be done with 'deferred / timed-out resume (w/
setTimeout(...,...);
).Does the module have a reset command? If so, I would send that before sending the command for turning on the oscillator.
Try something like that - my ugly chained steps with retries on timeouts...
Another - better looking approach would be nested/chained promises w/ (global) retries that is set / reset at the right spots.
PS: Code not tested (yet)