0
\$\begingroup\$
void __ISR(_UART1_VECTOR, ipl6) IntUart1Handler(void)     
{
    if(!INTGetFlag(INT_U1RX))
    {
        g_intraised++;
    }
    IFS0bits.U1RXIF=0;
}

uart initialization code

    U1BRG  = 0x0A;                                // baud rate 115200
    U1MODE = 0x8080;                              // set the ON bit and
    U1STA  = 0x5400;                             // set the transmit bit and  
    IEC0   = 0x08000010;//0x18000038;           // interrupt receive bit 
    IFS0   = 0x18000010;//0x18000038;           // interrupt receive flag 
    IPC6   = 0x0000001F;
\$\endgroup\$
  • \$\begingroup\$ Hi, welcome to EE.SE. You have to explain your question in a better way. More details are required. Also, you have to give more context of what you are getting and what is supposed to be! \$\endgroup\$ – Hazem Jan 4 at 10:29
  • \$\begingroup\$ I want to trigger the uart rx interrupt in pic32mx775f256h . but it is not happening. I have configured the uart according to the data sheet values. the tx interrupt is happening but rx is not happening \$\endgroup\$ – r0bin Jan 4 at 10:33
  • \$\begingroup\$ ur question is missing a lot of needed info. but quick thoughts: you're not reading U1RXREG and hence the interrupt (if set) would not be cleared. are you sure that the interrupt is not triggered? maybe the microcontroller is stuck in the interrupt. \$\endgroup\$ – fhlb Jan 4 at 10:55
  • \$\begingroup\$ also make sure you enabled the interrupt source enable (for U1RX) and that global interrupts are enable. you can place a breakpoint somewhere and check if there is actual data inside the U1RXREG. if the usart is configured correctly then you should receive data even if no interrupt is enabled (also URXDA should be set) \$\endgroup\$ – fhlb Jan 4 at 10:59
  • \$\begingroup\$ Thanks for your response... ! . I enabled the URXDA bit to 1 . but still no output \$\endgroup\$ – r0bin Jan 4 at 11:15
0
\$\begingroup\$

Your UART initialisation code should look like this, unless you are using Harmony framework in which case you need to check Harmony configuration, and harmony is quite buggy.

In either case you can reinit the uart after Harmony finished its own init.

void initU1ART(void) {
U1MODE = 0x0000;
U1STAbits.URXEN = 1; // Enable RX 
U1STAbits.UTXEN = 1; // Enable TX
U1BRG = ((_PBCLK / _UARTspeed) / 16) - 1;

IPC9bits.U1RXIP = 3;        // set IPL 3
IPC9bits.U1RXIS = 2;        // sub-priority 2

IFS1bits.U1RXIF = 0;        //!< Clear the Recieve Interrupt Flag
IEC1bits.U1RXIE = 1;        //!< Enable Recieve Interrupts
U1STAbits.URXISEL = 0;      //!where receive one character

U1MODEbits.ON = 1; //!< U1ART ON
U1STASET = 0x1400;
}

The important bit is IEC1bits.U1RXIE = 1; to enable the interrupt.

The IECxx register (as well as the others) might change from one chip to another, search "U1RXIE" on the datasheet to find the correct register for your chip.

EDIT:

Your interrupt is not enabled as IEC0 = 0x08000010; which makes bit 27 for the uart rx interrupt enable at 0.

You can add this after the your init: IEC0bits.U1ARXIE = 1;

U1BRG  = 0x0A;                                // baud rate 115200
U1MODE = 0x8080;                              // set the ON bit and
U1STA  = 0x5400;                             // set the transmit bit and  
IEC0   = 0x08000010;           // interrupt receive bit 
IEC0bits.U1ARXIE = 1;
IFS0   = 0x18000010;           // interrupt receive flag 
IPC6   = 0x0000001F;

EDIT:

Don't forget reseting the errors from the main loop:

if (U2STAbits.OERR) U2STAbits.OERR = 0;
if (U2STAbits.PERR) U2STAbits.PERR = 0;
if (U2STAbits.FERR) U2STAbits.FERR = 0;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.