#include "dsPIC_main_22_4_2018.h"
#include "dsPIC_main_22_4_2018_private.h"

/* Implement SPI 2 Interrupts */
void __attribute__((__interrupt__,__auto_psv__)) _SPI2Interrupt(void) /* SPI2 ISR */
{
  _SPI2IF = 0;

  /* Declaration of Variables */
  uint16_T tmp;
  switch (MCHP_SPI2_State)
  {
   case 0:                             /* Idle */
    break;

   case 1:                             /* Start a new SPI Sequence */
    LATEbits.LATE7 = 1;                /* switch RE7 to 1 */

    /* Delay */
    __delay32(1);                      /* Delay  */
    LATEbits.LATE7 = 0;                /* switch RE7 to 0 */

    /* Write only Sequence */
    SPI2BUF = SPI2_Buff8[0];

    /* Write only Sequence */
    SPI2BUF = SPI2_Buff8[1];

    /* Write only Sequence */
    SPI2BUF = SPI2_Buff8[2];
    MCHP_SPI2_State++;
    break;

   case 2:
    LATEbits.LATE7 = 1;                /* switch RE7 to 1 */
    tmp = SPI2BUF;
    tmp = SPI2BUF;
    tmp = SPI2BUF;
    MCHP_SPI2_State = 0;               /* End of SPI Sequence. SPI is available for a new sequence */
    break;

   default:                            /* Sequence finished */
    MCHP_SPI2_State = 0;               /* Should never happend */
    break;
  }                                    /* End of switch case sequence*/
}                                      /* Enf of interrupt */
