0
votes

Good afternoon,

I've configured my RX interrupt using the following simple function.

char c;
void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt( void ) 
{ 
    IFS0bits.U1RXIF = 0; // Clear RX Interrupt flag 
    c = U1RXREG;
} 

The problem is, UART transmits fine, but the interrupt service routine is never entered when it gets sent a character. I can trace with a scope that the character is actually sent without issues, but the interrupt does not get triggered.

The device used for communication is TTL-232R-3v3. The device is running at 3.3V The actual model number of the dspic33 is p33FJ128MC802 The programming environment is Mplab 8 and the compiled is XC16

Is there a missing setting to perhaps enable the interrupt? What could be missing?

Thanks, Here is the UART initialization code.

U1MODEbits.UARTEN = 0;  // Bit15 TX, RX DISABLED, ENABLE at end of func
U1MODEbits.USIDL = 0;   // Bit13 Continue in Idle
U1MODEbits.IREN = 0;    // Bit12 No IR translation
U1MODEbits.RTSMD = 0;   // Bit11 Simplex Mode
U1MODEbits.UEN = 0;     // Bits8,9 TX,RX enabled, CTS,RTS not
U1MODEbits.WAKE = 0;    // Bit7 No Wake up (since we don't sleep here)
U1MODEbits.LPBACK = 0;  // Bit6 No Loop Back
U1MODEbits.ABAUD = 0;   // Bit5 No Autobaud (would require sending '55')
U1MODEbits.URXINV = 0;  // Bit4 IdleState = 1  (for dsPIC)
U1MODEbits.BRGH = 0;    // Bit3 16 clocks per bit period
U1MODEbits.PDSEL = 0;   // Bits1,2 8bit, No Parity
U1MODEbits.STSEL = 0;   // Bit0 One Stop Bit

//  U1BRG = (Fcy / (16 * BaudRate)) - 1
//  U1BRG = (36850000 / (16 * 9600)) - 1
//  U1BRG = 238.908854 //Round to 239

U1BRG = 239;

U1STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
U1STAbits.UTXINV = 0;   //Bit14 N/A, IRDA config
U1STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
U1STAbits.UTXBRK = 0;   //Bit11 Disabled
U1STAbits.UTXEN = 0;    //Bit10 TX pins controlled by periph
U1STAbits.UTXBF = 0;    //Bit9 *Read Only Bit*
U1STAbits.TRMT = 0; //Bit8 *Read Only bit*
U1STAbits.URXISEL = 0;  //Bits6,7 Int. on character recieved
U1STAbits.ADDEN = 0;    //Bit5 Address Detect Disabled
U1STAbits.RIDLE = 0;    //Bit4 *Read Only Bit*
U1STAbits.PERR = 0;     //Bit3 *Read Only Bit*
U1STAbits.FERR = 0;     //Bit2 *Read Only Bit*
U1STAbits.OERR = 0;     //Bit1 *Read Only Bit*
U1STAbits.URXDA = 0;    //Bit0 *Read Only Bit*

RPINR18bits.U1RXR = 0b00010;//7; //RX is Pin RP2
RPOR1bits.RP3R = 0b00011;   //TX is pin RP3

U1MODEbits.UARTEN = 1;  // And turn the peripheral on
U1STAbits.UTXEN = 1;
1
1) Is code using interrupt driven output? Do those interrupts fire? 2) Other evidence any interrupts are triggered?chux - Reinstate Monica

1 Answers

0
votes

Check if the pin has additional functionality. Typically this is AD (analog pin). Make sure you turn off all analog, via the ADP or ANSEL registers (type and number varies depending on exact chip) E.g. I have this routine (I use both 33F and 33E and a high and low pincount one of both, hence the ifdefs)

void analogoff(void){
#if defined(__dsPIC33F__)
    ADPCFG  =0xFFFF;
    AD1PCFGH=0xFFFF;
    AD1PCFGL=0xFFFF;
#endif
#if defined(__dsPIC33E__)
#if !defined(__dsPIC33EP256MU806__)
    ANSELA=0;
#endif
    ANSELB=0;
    ANSELC=0;
    ANSELD=0;
    ANSELE=0;

    ANSELG=0;
#endif
}

Also, make absolutely sure the oscillator and thus the part's speed is correct, though if TX has the correct baudrate (scope!) that is probably ok.

My uart1 init:

U1BRG  = brgval;
U1MODE = 0x8000;        // Reset UART to 8-n-1, alt pins, and enable lowspeed (=bit 3)
U1MODEbits.USIDL =0;    // disable module when device is idle.
U1MODEbits.IREN  =0;    // IRDA disable
U1MODEbits.RTSMD =0;    // flow control mode (1= simplex mode)
U1MODEbits.UEN   =0;    // RTS en CTS controlled by PORTlatches
U1MODEbits.WAKE  =0;    // no wakeup enabled;
U1MODEbits.LPBACK=0;    // loopback disabled
U1MODEbits.ABAUD =0;    // no autobaud
#if !defined(__PIC24F__)
U1MODEbits.URXINV =0;   // RXINV inversion RX. (0= idle = '1')
#endif
U1MODEbits.BRGH  =1;    // high speed.
U1MODEbits.PDSEL =0;    // 8 bit no parity
U1MODEbits.STSEL =0;    // 1 stopbit.                 

U1STA  = 0x0440; 
U1STAbits.URXISEL0=0;// Reset status register and enable TX & RX. 
U1STAbits.URXISEL1=0;   // rx interrupt on a char. 
_U1RXIF=0;               // Clear UART RX Interrupt Flag
_U1RXIE = 1;             // Interruption active pour la reception
_U1RXIP=2;
_U1TXIP=2;
_U1TXIF=0;
_U1TXIE=0;             // only enabled when actually sending
U1MODEbits.UARTEN=1;