1
\$\begingroup\$

I am writing a program to send data from one microcontroller and receive the data using on another PIC32 microcontroller and display the received data on LCD. I am using UART2 of both PIC32MX to send and receive data and I am using UART interrupt at receiver side. I am not getting any data on receiving side :( and the LCD display shows nothing. The code is as follows:

The buffer size is 20.

function to Initialise UART

void UARTinitialization(void)
{
    PPSUnLock;
    PPSOutput(2,RPC13,U2TX);   //Assign U2TX to pin RPC13
    PPSInput(1,U2RX, RPC14);  //Assign U2RX to pin RPC14
    PPSLock;
    TRISCbits.TRISC14 = 1;
    TRISCbits.TRISC13 = 0;
    U2MODE           = 0;

    // enable TX and RX
    U2STA            = 0x1400;
    U2BRG            = Baud2BRG(115200,pbclk);

    // enable UART2
    IFS1bits.U2RXIF       = 0;
    IPC9bits.U2IP         = 2;
    IPC9bits.U2IS         = 1;
    IEC1bits.U2RXIE       = 1;
    U2MODESET             = 0x8000;
    rxIndex               = 0;

    //RS485                 = READ;
}//END of UART Initialization

Function to display received char:

void Display(void)
{
    if(UART_Flag == 1)         //check whether the program enters into the ISR
    {
        int i;
        for (i=0; i<BUFFER_SIZE; i++)
        {
            LCDinitWriteChar(rxBuffer[i]);
            if (rxBuffer[i] == '\0')
                break;
        }
        UART_Flag = 0;
    }
}

Function to send the data (used at transmitter side):

void writeUART(char *string,size_t size)
{
    while(size > 0)
    {
        while(U2STAbits.UTXBF);

        // put data in to transmitt register
        U2TXREG = *string;
       string++;
       size--;
    }
    // wait for complete transmission of data
    while(!U2STAbits.TRMT); 
}

ISR Code:

void __ISR(_UART_2_VECTOR, IPL6SRS) _U2Interrupt(void)
{
    //Receive Buffer Overrun Error Status bit.
    if(U2STAbits.OERR)
        U2STAbits.OERR = 0;
    else
        if(IFS1bits.U2RXIF)
        {
            rxBuffer[rxIndex]  = U2RXREG;
            // rxIndex++;
            if(rxBuffer[0]!='*')
            {
                rxIndex = 0;
            }
            else
            {
                rxIndex++;
            }
            UART_Flag = 1;
        }
        IFS1bits.U2RXIF = 0;
    }

main function at receiver side:

int main(int argc, char** argv) {
    pbclk = SYSTEMConfigPerformance(80000000);
    UARTinitialization();
    LCDInit();            // LCD Intialization
    clearScreen();
    while(1)
    {
       if (U2STAbits.OERR) U2STAbits.OERR = 0;
       if (U2STAbits.PERR) U2STAbits.PERR = 0;
       if (U2STAbits.FERR) U2STAbits.FERR = 0;
       Display();              //function to display received data
       LCDinitClear();
    }
    return (EXIT_SUCCESS);
}
\$\endgroup\$
  • \$\begingroup\$ Are you two in the same class? \$\endgroup\$ – JRE Jan 4 at 12:31
  • \$\begingroup\$ Specify which chip exactly you are using \$\endgroup\$ – Damien Jan 4 at 12:41
  • \$\begingroup\$ @JRE thought the same but they are not using the same chip, this one has pin mapping feature and not the other one. \$\endgroup\$ – Damien Jan 4 at 12:52
0
\$\begingroup\$

Make sure to keep clearing the UART errors from the main while as it can stop the uart:

if (U2STAbits.OERR) U2STAbits.OERR = 0;
if (U2STAbits.PERR) U2STAbits.PERR = 0;
if (U2STAbits.FERR) U2STAbits.FERR = 0;

Where do you call void Display(void) method from ?

\$\endgroup\$
  • \$\begingroup\$ Thanks for your suggestion! Actually i am calling the display function from main() to print the received characters on LCD! \$\endgroup\$ – Sanket Uttarwar Jan 5 at 4:10
  • \$\begingroup\$ I have posted main program of receiver in my post! \$\endgroup\$ – Sanket Uttarwar Jan 5 at 8:21

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.