This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSC (MicroSystem Controller) family - Using SPI within AI

Dear Champion,

I'm facing some obstacle while trying to send SPI (Master with ESPIT and ESPIR disabled) within ISR (PAI). The auxillary interrupts in used are:

1) One Millisecond

2) ADC Conversion

3) Accumulator

4) Second

What puzzle me is it works fine when I call my SPI send function (Telemetry_ConfigureMUX) within "Second" ISR while not for the rest. Could it be the depth of nesting functions?

void SPI_Init()
{
 PDCON&=~0x03; // turns on System Timer and SPI
 P1DDRH=0x75; //CMOS output for P1.7, P1.5 and P1.4
 SPICON=0x44; // Divide 8, FIFO off, msb, master, CPHA=0 
 SPITCON=0x28; // SCK driver on
}

void AuxISR(void) interrupt 6 using 1
{
 long int dummy;
 unsigned char clearInterrupt;


 switch (PAI) {
    /* One Millisecond System Timer IRQ */ 
  case 5:
   clearInterrupt = MSINT; //Dummy read clears the interrupt condition   
   Uplink_ms_ISR();
  break;
  /* Analog-to-Digital Conversion IRQ */ 
  case 6:
  dummy=ADRESL; // clear the interrupt condition   
  VibrationADCISR();
  Telemetry_ConfigureMUX(USMUXA0, USMUXA1);
  PressureADCISR();
  AnalogueADCISR();
  Telemetry_ConfigureMUX(USMUXA0, USMUXA1);
  break;
  /* Accumulator IRQ Pending */ 
  case 7:
  dummy=SUMR0; // clear the summation interrupt condition
  PressureSUMISR();
  Telemetry_ConfigureMUX(USMUXA0, USMUXA1);
  AnalogueSUMISR();
  break;
  /* Second */
  case 8:
  {  
   dummy=SECINT; // read to clear seconds interrupt flag
   //Telemetry_GetFirmware();
   //Telemetry_SendPacket();
   //Telemetry_ConfigureMUX(0x00, 0x00);
   //Telemetry_ConfigureMUX(0x00, 0x01);
   //Telemetry_ConfigureMUX(0x01, 0x00);
   //Telemetry_ConfigureMUX(0x01, 0x01);
  }
  break;
 }
 AI = 0;     // Clear AI before returning
}


void Telemetry_ConfigureMUX(unsigned char MUX_PIN_A0, unsigned char MUX_PIN_A1)
{
 SS=0;
 while (!(AIE & 0x08)); 
  SPIDATA=0x8D;
 //while (!(AIE & 0x04)); 
 //while (!(AIE & 0x08)); 
  SPIDATA=((MUX_PIN_A1<<1)&0x2)|(MUX_PIN_A0&0x1);
 while (!(AIE & 0x04));
 SPI_Delay(1);
 SS=1;
}

void SPI_Delay(char InstructionCycle)
{
 char waitCnt;
 
 for(waitCnt=0;waitCnt<InstructionCycle;waitCnt++)
 _nop_(); 
}

Beside this I also observed that SPI deselect (SS=1) happened too soon (deselect on the middle of 2nd byte being transfer). I will have to place delay. What would be the reason of this out of sync SS? Thanks!