4
votes

I'm using a PIC32MX795F512L SPI3 module in slave mode. My master is sending data over the SPI line but my slave's interrupt service routine is never being called. The RX interrupt flag is being set in hardware on the slave side and I can read the SPI3BUF and get the correct value, but the ISR is still not being called.

Here's my spi init code:

void InitSPI3()
{
    int rData;

    IEC0CLR=0x1c000000;//Disable Rx Tx, Error interrupts
    SPI3CON = 0; // Stops and resets the SPI3.
    SPI3BRG = 0;
    rData=SPI3BUF;// clears the receive buffer
    IFS0CLR = 0x1c000000;//Clear interrupt flags
    IPC6CLR=0x0000001f;// clear the priority
    //ipl7, subpri 0
    IPC6bits.SPI3IP = 7;
    IPC6bits.SPI3IS = 0;
    //Enable Rx Tx, Error interrupts
    IEC0bits.SPI3RXIE = 1;
    IEC0bits.SPI3TXIE = 1;
    //IEC0bits.SPI3EIE = 1;

    SPI3CONbits.CKE = 1;
    SPI3CONbits.SSEN = 1;

    SPI3STATbits.SPIROV = 0;// clear the Overflow

    //Enable SPI
    SPI3CONbits.ON = 1;

    //** from now on, the device is ready to receive and transmit data (slave mode)...
}

And here's my ISR

void    __ISR(_SPI_3_VECTOR, ipl7) _SPI3Interrupt()
{
    SET_D2();
    SET_D1();

    // RX INTERRUPT
    if(IFS0bits.SPI3RXIF) // receive data available in SPI3BUF Rx buffer
    {
        SPI_Rx_Interrupt();
    }

    // TX INTERRUPT
    if(IFS0bits.SPI3TXIF) // space available in SPI3BUF Tx buffer
    {
        SPI_Tx_Interrupt();
    }


    IFS0CLR = 0x1c000000; // clear SPI3 interrupts

} // end ISR

I'm using MPLAB X and the C32 compiler. I've been banging my head against the wall for 4 hours on this.

2
Are other interrupts occurring? Most interrupt controllers/processors have some sort of global interrupt enable/disable. I think your question is already answered on microchip.com/forums/m647728-print.aspx in any case.Clifford

2 Answers

1
votes

Things to check:
1 - Is there a global interrupt mask you need to modify to let that one work?
2 - Is there an interrupt level/priority mask that needs to be modified?
3 - Have you given the interrupt a unique level/priority, some micros will not allow two interrupts to share the same lev&pri and some will default to junk or non-working values.

0
votes

Some other things to look at it:

  1. Check the errata for your chip. Microchip has a history of SPI-related silicon issues in PICs.

  2. Take a look at this discussion: http://www.microchip.com/forums/m573732.aspx. It is mostly directed to a peripheral chip, but the SPIxSTATbits.SPITBE and SPIxSTATbits.SPIRBF discussion may give you something to go on.