Hot!PIC32MZ EF SK & SPI Slave Interrupt

Author
PICcadillyCircus
Starting Member
  • Total Posts : 42
  • Reward points : 0
  • Joined: 2017/04/11 11:12:29
  • Location: 0
  • Status: offline
2017/07/28 11:19:16 (permalink)
0

PIC32MZ EF SK & SPI Slave Interrupt

I am trying to get the slave end of SPI comms between two PIC32MZ EF starter kits going. I can output the data and scope it on the input to the receiving starter kit. When the slave side code runs in debug mode however, I get no interrupts, but a _general_exception_handler instead.
 
I have scoped the following connections to confirm correctness:
SS3 >> RG6
SCK3 >> RB14
SDI3 >> RA14
SDO3 >> RD10
 
SDI3Rbits.SDI3R = 0x000D; // Set RA14 for SDI3
RPD10Rbits.RPD10R = 0x0007; // Set RD10 for SDO3
SS3Rbits.SS3R = 0x0001; // Set RG6 for CS3

 
void Init_Spi_3 (void){
    
    CFGCONbits.JTAGEN = 0;
    
    SPI3CONbits.ON = 0; // Stop the SPI module.

    IEC4bits.SPI3EIE = 0; // Disable the SPI fault interrupt.
    IEC4bits.SPI3RXIE = 0; // Disable the SPI RX interrupt.
    IEC4bits.SPI3TXIE = 0; // Disable the SPI TX interrupt.
    
    IFS4bits.SPI3EIF = 0; // Clear the SPI fault interrupt.
    IFS4bits.SPI3RXIF = 0; // Clear the SPI RX interrupt.
    IFS4bits.SPI3TXIF = 0; // Clear the SPI TX interrupt.
    
    SPI3STATbits.SPIROV = 0; // Clear the RX overflow flag.
    
    uint16_t rxData;
    rxData = SPI3BUF; // Read the RX buffer to clear it.
    
    IPC38bits.SPI3EIP = 3; // SPI error interrupt priority.
    IPC38bits.SPI3EIS = 1; // SPI error interrupt sub-priority.
    
    IPC38bits.SPI3EIP = 7; // SPI RX interrupt priority.
    IPC38bits.SPI3RXIS = 3; // SPI RX interrupt priority.
    
    IPC39bits.SPI3TXIP = 7; // SPI TX interrupt priority.
    IPC39bits.SPI3TXIS = 3; // SPI TX interrupt sub-priority.
    
    IEC4bits.SPI3EIE = 1; // Enable the SPI fault interrupt.
    IEC4bits.SPI3RXIE = 1; // Enable the SPI RX interrupt.
    //IEC4bits.SPI3TXIE = 1; // Enable the SPI TX interrupt.
    
    SPI3CONbits.SRXISEL = 3; // generate interrupt when RX buffer is full
    SPI3CONbits.SSEN = 1; // Slave Select enable.
    
    SPI3CONbits.MODE16 = 1; // Enable 16-bit mode.
    //SPI3CONbits.MODE32 = 1; // Enable 32-bit mode.
    
    SPI3CONbits.ON = 1; // Start the SPI module.
}

 
void __ISR(_SPI3_FAULT_VECTOR, ipl3AUTO) SPI3_FAULT_IntHandler (void){

    IFS4bits.SPI3EIF = 0; // Clear the interrupt flag.
}


void __ISR(_SPI3_TX_VECTOR, ipl7AUTO) SPI3_TX_IntHandler (void){

    IFS4bits.SPI3TXIF = 0; // Clear the interrupt flag.
}



void __ISR(_SPI3_RX_VECTOR, ipl7AUTO) SPI3_RX_IntHandler (void){
    
 
    IFS4bits.SPI3RXIF = 0; // Clear the interrupt flag.
}

 
Any suggestions would be appreciated.
#1

5 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2242
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32MZ EF SK & SPI Slave Interrupt 2017/07/28 13:27:48 (permalink)
    +3 (3)
    IPC38bits.SPI3EIP = 3; // SPI error interrupt priority.
    IPC38bits.SPI3EIP = 7; // SPI RX interrupt priority.

     
    #2
    PICcadillyCircus
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2017/04/11 11:12:29
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF SK & SPI Slave Interrupt 2017/07/31 05:36:56 (permalink)
    +2 (2)
    andersm
    IPC38bits.SPI3EIP = 3; // SPI error interrupt priority.
     
    IPC38bits.SPI3EIP = 7; // SPI RX interrupt priority.

     


    Oh my gosh... Thanks, dude.
    #3
    GrahamH
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2010/04/23 20:37:12
    • Location: Austin, TX
    • Status: offline
    Re: PIC32MZ EF SK & SPI Slave Interrupt 2017/08/13 07:00:36 (permalink)
    0
    In an example like this, where you are not using Harmony, and writing lower level C-language code for an PIC32MZ application, where are the interrupt functions declared?
     
    So, if I have the ISR below, where is 'SPI3_RX_IntHandler()' declared?
     
    Are these already pre-defined in some processor definition file, so there is a listing somewhere of what the valid function names are?
     
    Or is there a header file somewhere that I need to add the declaration to?
     
    Or does it matter, and the __ISR(  , ) does something magic behind the curtain?
     
    Example from the above discussion:
     
    void __ISR(_SPI3_RX_VECTOR, ipl7AUTO) SPI3_RX_IntHandler (void)
    {
        IFS4bits.SPI3RXIF = 0; // Clear the interrupt flag.
    }

    --- Graham

    ==

    #4
    andersm
    Super Member
    • Total Posts : 2242
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32MZ EF SK & SPI Slave Interrupt 2017/08/13 07:36:52 (permalink)
    +2 (2)
    The name of the ISR function can be anything, it's the vector number (_SPI3_RX_VECTOR in your example) that matters. The vectors are enumerated in the datasheet, and the vector number macros are defined in the processor-specific header file. There's some behind-the-curtains magic involved in setting up eg. the vector offset registers that you don't need to worry about, but if you really want to know extract the pic32-libs.zip file found inside the XC32 install tree and read through the startup code and linker scripts.
    #5
    GrahamH
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2010/04/23 20:37:12
    • Location: Austin, TX
    • Status: offline
    Re: PIC32MZ EF SK & SPI Slave Interrupt 2017/08/13 10:00:40 (permalink)
    +1 (1)
    That is kind of what I suspected.  
    But once again, the Microchip docs don't really make it clear.
     
    Thanks for the response.
     
    --- Graham
     
    ==
     
    #6
    Jump to:
    © 2017 APG vNext Commercial Version 4.5