[sdiy] MIDI I/O c code..

Jean-Pierre Desrochers jpdesroc at oricom.ca
Fri Mar 20 15:55:49 CET 2020


Here is my complete interrupt routine,

This routine could be called by the USART, Timer0 or Timer1

And so reacts on which is calling..

Problem doing that ?

And yes I have to check for any USART overrun OERR flag here

To see if it sometimes happens..

 

///////////////////////////////

// ----------------------------

//  interrupt service routine

// ----------------------------

///////////////////////////////                              

 

void interrupt tmr0_USART_isr (void) 

 {

  char  x;      // intermediate byte value

 

  // RS232 receive interrupt                       

  if (RCIF == TRUE && RCIE == TRUE) 

   {                                                     

 

    if (OERR == TRUE)     // overrun, reset UART

     {                                              

      CREN = FALSE;       // disable UART

      CREN = TRUE;        // re-enable UART

     }                                         

   

    else 

     { 

      x = RCREG;

      if((x & 0xF0) != 0xF0)    // Ignore all 1 byte commands

       {                                  // data without errors

        rcvbuf[rcvoffset] = x;            // move byte to rcv buffer                                                    

        rcvoffset++;                     // offset next byte

 

        if (rcvoffset == RCVBUFSIZE)    // beyond buffer boundary

          rcvoffset = 0;                // wrap to begin

       }  

 

      MIDI_ACTIVITY_LED = ON; //RC0 = 0; // Set led MIDI ACTIVITY to ON

      TMR0 = 0; // restart timer0

      T0IE=1;   // Activates overflow interrupt of TMR0 register

      RCIF = 0; // Erase MIDI RX flag

      }

 

 

    }

 

  // Timer0 interrupt

  if (T0IF == TRUE)

   {

    MIDI_ACTIVITY_LED = OFF; //RC0 = 1; // Shut down MIDI ACTIVITY led

    T0IF = 0;

    T0IE=0; // Prevent overflow interrupt of TMR0 register

   }

 

 

  // Timer1 interrupt

  if (TMR1IF == TRUE)

   {

    TIMER1_mult++;

    if(TIMER1_mult == TIMER1_MUL_MAX)

     {

      TIMER1_mult = 0;

      ARPEGGIO_LED ^= 1;  // RC1 ^= 1;

     }

    TMR1H = arpeggio_rate;

    TMR1L = 0;

    TMR1IF = 0;

   }

 

}

 

 

 

 

*************************************************************************

-----Message d'origine-----
De : Synth-diy [mailto:synth-diy-bounces at synth-diy.org] De la part de René Schmitz
Envoyé : 20 mars 2020 10:49
À : synth-diy at synth-diy.org
Objet : Re: [sdiy] MIDI I/O c code..

 

On 20.03.2020 15:11, Jean-Pierre Desrochers wrote:

> Hi Mikko,

> 

> Here is my USART Rx  interrupt routine :

> Maybe you’ll spot any errors or things I forgot.. ??

 

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.)

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.)

 

Best,

  René

 

--

synth at schmitzbits.de

http://schmitzbits.de

_______________________________________________

Synth-diy mailing list

Synth-diy at synth-diy.org

http://synth-diy.org/mailman/listinfo/synth-diy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20200320/35e2fcb8/attachment.htm>


More information about the Synth-diy mailing list