<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 20 Mar 2020, at 14:48, René Schmitz <<a href="mailto:synth@schmitzbits.de" class="">synth@schmitzbits.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 20.03.2020 15:11, Jean-Pierre Desrochers wrote:<br class=""><blockquote type="cite" class="">Hi Mikko,<br class="">Here is my USART Rx interrupt routine :<br class="">Maybe you’ll spot any errors or things I forgot.. ??<br class=""></blockquote><br class="">Without looking at the interrupt setup code I'm not sure, but it seems you check the USART in a Timer ISR is that the intention? (by how you named things.)<br class="">if so, it could be that sometimes you miss a byte because there is an overrun between two timer cycles. have you tried seeing if the overrun flag is actually set? (maybe toggle a pin so you can check with a scope.)<br class=""><br class="">Best,<br class=""> René</div></div></blockquote><br class=""></div></div><div>+1agree with René - what’s going on with Timer1?<div class=""><br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>You’ve got a UART Rx interrupt, so use that instead. When the byte comes in, stick it in the buffer like you’re doing. Maybe use the Timer interupt to process MIDI messages every couple of milliseconds or so (It takes a millisecond for a full note-on message to arrive anyway, so there’s not *much* point going faster). If you use the Rx interrupt, you also don’t need to check RCIF and RCIE on entry, which saves you time.</div></div></div><div class=""><br class="webkit-block-placeholder"></div><div class="">I’d also use modulus arithmetic to limit the length of the buffer (especially since your buffer is 32 bytes not something awkward like 57). That saves an “if” statement:</div><div class=""><br class=""></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;" class=""><b class=""><i class=""><span lang="EN-CA" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""> rcvbuf[rcvoffset & 31] = x; // move byte to rcv buffer, limited to index 0-31 <o:p class=""></o:p></span></i></b></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;" class=""><b class=""><i class=""><span lang="EN-CA" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""> rcvoffset++; // offset next byte</span></i></b></div></div><div class=""><br class=""></div><div class=""><br class="webkit-block-placeholder"></div></div><div class="">Personally, I’d probably drop some of the safety checking the various error flags in the interrupt. You could check those in the processing routine instead. They’ll just be slowing things down and possibly making the events they check for more likely to occur!</div><div class=""><br class=""></div><div class="">Tom</div><div class=""><br class=""></div></div></body></html>