PIC32MZ UART RX中断

时间:2017-12-29 02:44:59

标签: interrupt uart microchip pic32

从PIC32MX移植到MZ(PIC32MZ2048EFG100)并且正在撞击墙壁试图在UART3上生成简单的RX中断。请参阅下面的代码。

void main(void} {
    __builtin_disable_interrupts();
    //Ensuring all pins config as digital
    ANSELA = 0x0000;
    ANSELB = 0x0000;
    ANSELC = 0x0000;
    ANSELD = 0x0000;
    ANSELE = 0x0000;
    ANSELF = 0x0000;
    ANSELG = 0x0000;

    //Convenient macrso to do IOUNLOCK
    #define PPSUnLock() {SYSKEY=0x0;SYSKEY=0xAA996655;SYSKEY=0x556699AA;CFGCONbits.IOLOCK=0;} 
    #define PPSLock() {SYSKEY=0x0;SYSKEY=0xAA996655;SYSKEY=0x556699AA;CFGCONbits.IOLOCK=1;}

    //Peripheral Pin Select (PPS) Settings for UART3
    PPSUnLock();
    U3RXRbits.U3RXR = 0b1010;
    RPA14Rbits.RPA14R = 0b0001;
    PPSLock();

    //Config UART3
    U3MODEbits.UEN0 = 0;  //no flow control
    U3MODEbits.UEN1 = 0;
    U3MODEbits.LPBACK = 0; // no loopback
    U3MODEbits.ABAUD = 0; //no autobaud
    U3MODEbits.BRGH = 0;
    U3MODEbits.PDSEL0 = 0; //8 data bits, no parity
    U3MODEbits.PDSEL1 = 0;
    U3MODEbits.STSEL = 0; // 1 stop bit

    U3STAbits.URXISEL0 = 0; //RX Interrupt on first byte in FIFO
    U3STAbits.URXISEL1 = 0;

    U3BRG = CLOSEST_UBRG_VALUE115200; //Macro defined elsewhere, but it works

    //Int priorities
    IPC39bits.U3EIP = 6;
    IPC39bits.U3EIS = 3;

    //Int flags
    IFS4bits.U3RXIF = 0;

    //Int enable/disable
    IEC4bits.U3EIE = 0;
    IEC4bits.U3TXIE = 0;
    IEC4bits.U3RXIE = 1; //Enable int on RX

    //Enable multi-vector interrupts
    INTCONSET = _INTCON_MVEC_MASK;
    __builtin_enable_interrupts();

    //Turn on UART3
    U3STAbits.URXEN = 1;
    U3STAbits.UTXEN = 1;
    U3MODEbits.ON = 1;

    UART_txEXTCOMandWait('A'); //Function defined elsewhere - I get successful byte "A" sent to my terminal. So TX works.


    while(1){Nop();}; //wait in endless loop for interrupt to occur on keystroke
}

以下是我的ISR:

void __ISR_AT_VECTOR (_UART3_RX_VECTOR, IPL6SOFT) U3Interrupt(void) {
    unsigned int test=0;
    Nop(); //Setting a breakpoint here

}

我成功地看到了一个" A"在运行程序时在终端屏幕上,因此TX的设置正确。在终端屏幕中键入文本不会产生中断。已经验证信号正在进入PIC32。

我在这里缺少什么?我花了很多时间在一些应该是微不足道的事情上。

谢谢你们。

1 个答案:

答案 0 :(得分:0)

想出来......应该是:

 //Int priorities
 IPC39bits.U3EIP = 6;
 IPC39bits.U3EIS = 3;

多年来有趣的是PIC32MX的生产方式。