MIDI-to-I2C firmware troubleshooting/debugging

In my MIDI-to-I2C experiments, sometimes the ER-301 gets in a bad state where it responds improperly to Teletype ‘SC’ commands. My converter translates incoming MIDI notes into SC.CV.SET commands for pitch and velocity and an SC.TR command for the gate. The behavior I’m seeing is that SC.TR signals are seemingly inverted with respect to the incoming MIDI notes, if that makes sense. As far as I can tell, only the SC.TR commands are affected.

I’m clocking the I2C bus at 100kHz, I’m using I2C_OP_MODE_IMM, and I’m using the blocking versions of the transmit functions. I’ve put error checking in my code, but no I2C errors appear even when the problematic behavior manifests.

The problem occurs pretty infrequently. It might take minutes to occur, or it might run with no problems for hours before finally hitting a snag. I was using the low-latency version of 0.4.11 initially, but I switched to the 96kHz firmware and the issue still presents itself. I also tried Drillionaire’s firmware but the result is the same.

Any thoughts, @odevices?

P.S., I somewhat ruled out issues with my Teensy firmware by rebooting the ER-301 but not the Teensy after the problem occurs, and triggering goes back to normal. So I don’t think I’m sending bogus I2C commands.