• What you're doing looks ok - but you're doing this from an interrupt?

    It's likely that what is happening is Espruino does something like a garbage collection pass outside of an interrupt (very occasionally), but then if your interrupt happens while that is running, it may not be able to get data reliably and so might break.

    Usually that's ok (apart from lost data), but if you're printing data at a high IRQ level and then the output buffer gets full, you can get deadlocked.

    If you're on the Nucleo then I guess you could run a debugger and find out what/where the error occurred.

    However when implementing Bluetooth I decided a while back that allocating JS variables in interrupts just wasn't working reliably. Especially as it looks like you're only sending chunks of 11 bytes I'd just define a static buffer, write the data to that in an IRQ, and then handle that in an 'idle' handler.

    ... or Bluetooth support actually writes data into the input buffer (eg. https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/bluetooth.c#L211) but I think that's overkill for what you want here.


Avatar for Gordon @Gordon started