Hot!Interrupt structure framework example for K42 in MPLAB X

Author
MChiper
Starting Member
  • Total Posts : 23
  • Reward points : 0
  • Status: offline
2018/02/12 09:56:58 (permalink)
0

Interrupt structure framework example for K42 in MPLAB X

I'm porting some code from an 18F25K22 to a 18F25K42, and this forces me to move to MPLAB X now.  I'm unsure how to setup the vectored interrupt handlers.  Anyone have an example they can share?
Thanks.
 
#1

5 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 912
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: Interrupt structure framework example for K42 in MPLAB X 2018/02/12 12:16:22 (permalink)
    0
    For "irq(xxx)" - all the xxx arguments are in the pic18_chipinfo.html file in your xc8 installation folder (under docs)
     
    #define IVT_BASE    0x808  //8


    // IVT location - using 0x000808 as bootloader is in 0-0x7ff
    void init_int (void) {
        INTCON0bits.IPEN = 1;            // enable priorities
        bool state    = (bool)GIE;        // save interrupt state
        IVTLOCK        = 0x55;
        IVTLOCK        = 0xaa;
        IVTLOCKbits.IVTLOCKED = 0x00;    // unlock IVT
        IVTBASE        = (unsigned short long)IVT_BASE;    // set IVT to 0x808
        IVTLOCK        = 0x55;
        IVTLOCK        = 0xAA;
        IVTLOCKbits.IVTLOCKED = 0x01;    // lock IVT
        GIE            = state;            // restore interrupt state
    }

    // interrupt servicing
    void __interrupt(irq(IRQ_U1TX),base(IVT_BASE),low_priority) uart_tx_isr() {
        if (xhd == xtl) {
            U1TXIE    = 0;                    // if hd==tl, nothing left to transmit
        } else {
            U1TXB    = xbfr[xtl];                // send next character
            xtl        = (xtl + 1u) MOD_XBFR_SIZE;    // and update tail pointer
         }
    }

    void __interrupt(irq(IRQ_U1RX),base(IVT_BASE),low_priority) uart_rx_isr() {
        rbfr[rhd]    = U1RXB;                    // put rcvd byte at buffer head
        rhd            = (rhd + 1u) MOD_RBFR_SIZE;    // and update head pointer
    }

    post edited by mbrowning - 2018/02/12 12:22:14

    Can't remember. I've slept since then - Mark
    #2
    MChiper
    Starting Member
    • Total Posts : 23
    • Reward points : 0
    • Status: offline
    Re: Interrupt structure framework example for K42 in MPLAB X 2018/02/13 09:12:15 (permalink)
    0
    Thanks!
    I'm curious how you know/found this out.  I have not seen this in the mplabx users manual, so wondering what doc(s) are supposed to show me this.
     
    #3
    GeorgePauley
    Moderator
    • Total Posts : 919
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: Interrupt structure framework example for K42 in MPLAB X 2018/02/13 09:21:05 (permalink)
    0
    Setting up interrupt vectors is a compiler issue, not an MPLAB X issue.  MPLAB X is an IDE that makes use of compilers.  You should be able to use the compiler for the K42 device as you used for the K22 device.
    #4
    MChiper
    Starting Member
    • Total Posts : 23
    • Reward points : 0
    • Status: offline
    Re: Interrupt structure framework example for K42 in MPLAB X 2018/02/13 09:46:26 (permalink)
    0
    Oops... I did mean compiler guide.  I'm confused as I'm switching IDEs and to a chip that uses vector interrupts instead of just high/low priority.
     
    #5
    mbrowning
    Just a Member
    • Total Posts : 912
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: Interrupt structure framework example for K42 in MPLAB X 2018/02/13 10:26:00 (permalink)
    0
    I guess I just looked at files in the "docs" folder of XC8 until I found what I needed. Also, the disassembly listing is very useful.
    The XC8 user guide is pretty clear on vectored interrupts using C. For specific data about a given device, "pic(18)_chipinfo.html" will take you to the html page for your chip with all the config pragmas and interrupt assignments.
     
     

    Can't remember. I've slept since then - Mark
    #6
    Jump to:
    © 2018 APG vNext Trial Version 4.5