• AVR Freaks

Hot!PIC32MZ UART interrupt without Harmony

Author
LECAT
Junior Member
  • Total Posts : 116
  • Reward points : 0
  • Joined: 2012/01/24 03:23:44
  • Location: MONTPELLIER FRANCE
  • Status: offline
2019/02/05 02:35:38 (permalink)
0

PIC32MZ UART interrupt without Harmony

Hello everyone
 
I put into operation UART1 and UART3 on the Curiosity PIC32MZ but without harmony.
I'm searching for a  code to put an interruption on UART1 or UART3
 thank you in advance
 
Franck
#1

3 Replies Related Threads

    MisterHemi
    Senior Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: PIC32MZ UART interrupt without Harmony 2019/02/05 09:26:21 (permalink)
    5 (1)
    The XC32 interrupt vector names can be found in data sheet 
    DS60001320D on page 122 (for the UARTs).
     
    An example would be similar to this:

     
    void __ISR(_UART1_RX_VECTOR,ipl4AUTO) _UART1_RX_Handler(void){
     
     // Insert your code here to handle the received data.
     
    IFS3bits.U1RXIF = 0; // Here you reset the interrupt flag.
     
    }
     

    Where "__ISR" indicates its an Interrupt Service Routine,
    and "_UART1_RX_VECTOR" is the vector name for the device,
    and "ipl4AUTO" sets the interrupt priority level and type for the ISR.
     
    That example only shows how to setup the interrupt when data is received. You would need to look at the data sheet to find the correct vector name for a transmit interrupt, and for the other UARTs though they're very similar, except the UART number.
     
    Also you would need to configure the UART and enable it's interrupt. For the above example it would be as follows:

     
    IEC3bits.U1RXIE = 1; // Enable UART1 RX (Receive) interrupt.
     

     
    The table listed in the data sheet DS60001320D on page 122 also has a table with the registers for the interrupt and the registers that enable the interrupt for the corresponding device (in the case UART1).
     
    You may also need to find the register for the device (e.g.- UART1) which sets the priority level (priority and sub-priority) for it's interrupt:

     
    IPC28bits.U1RXIP = 4; // Set the interrupt priority level to 4.
     
    IPC28bits.U1RXIS = 0; // Set the interrupt sub-priority to 0 (zero).
     

     

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #2
    LECAT
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2012/01/24 03:23:44
    • Location: MONTPELLIER FRANCE
    • Status: offline
    Re: PIC32MZ UART interrupt without Harmony 2019/02/06 13:07:11 (permalink)
    0
    Thank you very much for this answer
    Are there very simple examples like the C32 compiler?
    to enable or disable interrupts
    Thank you
    Franck
    ************************************************************************
    INTEnable(INT_SOURCE_UART_RX(UART1), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0);
    #3
    MisterHemi
    Senior Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: PIC32MZ UART interrupt without Harmony 2019/02/07 21:55:47 (permalink)
    0
    You would need to initialize the UART (read the data sheet for the registers). 
    In one function I wrote for the PIC32MZ at the end of the initialization I cleared the RX interrupt flag and enabled the RX interrupt using the following:

    IFS3bits.U1RXIF = 0; // Clear UART-1 Receive Interrupt flag.
    IEC3bits.U1RXIE = 1; // Enable UART-1 Receive Interrupts.

     
    For TX (transmit) interrupts, you'd use:

    IFS3bits.U1TXIF = 0; // Clear UART-1 Transmit Interrupt flag.
    IEC3bits.U1TXIE = 1;  // Enable UART-1 Transmit Interrupts.


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5