Electronic – PIC24FJ128GA202 UART2 and UART3 not working

cgprsgpspic

I am working in pic24fj128ga202 microcontroller with L80 and M95 module. here L80 module connected with uart2 and M95 module connected with uart3. now uart1 working normally but uart2 and uart3 not working (i.e) I didn't get gps and gprs data .below I have attached both uart.h and ioconfig.h files
main.c

#include "p24FJ128GA202.h"           
#include <stdio.h> 
#define led PORTAbits.RA2
#include "UART.h"
#include "IOCONFIG.h"
int main()
{
    GSMPwrkey=1;
    init_processor();
    uartx1( uart2rx());
   return 0;
}

UART.h
#include<stdio.h>
/* transmit a character in uart1 */
void uartx1(char in_c)
{
    while(U1STAbits.UTXBF == 1);
    U1TXREG = in_c;
}
/* transmit a character in uart1 */
void uartx2(char in_c)
{
    while(U2STAbits.UTXBF == 1);
    U2TXREG = in_c;
}
/* transmit a character in uart3 */
void uartx3( char in_c)
{             
    while(U3STAbits.UTXBF == 1);
    U3TXREG = in_c;       
}
/* Receive a character in uart1 */
char uart1rx()
{
    char c;
    while(U1STAbits.URXDA == 0);
    c = U1RXREG;
    return c;       
}
/* Receive a character in uart2 */
char uart2rx()
{
    char c;
    while(U2STAbits.URXDA == 0); 
    c =U2RXREG; 
    return c;
}
/* Receive a character in uart3 */
char uart3rx()
{  
    char c;
    while(U3STAbits.URXDA == 0); 
    return U3RXREG; 
    return c;
}
/* transmit a string in uart1 */
void uartstr1( char *s)
{
    while(*s!='\0')
    {
        uartx1(*s);
        s++;
    }
}
/* transmit a string in uart3 */
void uartstr3( char *s)
{
    while(*s!='\0')
    {
        uartx3(*s);
        s++;
    }
}


IOCONFIG.h

#include<stdio.h>
#include<stdint.h>
#define GSMPwrkey PORTBbits.RB12
#define GPSreset PORTBbits.RB15
void Timer1DelaymsInit(void);
void Delayms(uint16_t delay);
void init_Processor(void);
void Timer1DelaymsInit(void)
{
    T1CONbits.TCKPS = 0; //Timer1 Prescale Select bit
    T1CONbits.TCS = 0;   //Timer1 Clock source(FOSC/2)
    PR1 = 3760;
    TMR1 = 0;
    IEC0bits.T1IE = 0;
    T1CONbits.TON = 1;

}
void Delayms(uint16_t delay)
{

    while(delay>0)
    {
        TMR1 = 0;
        IEC0bits.T1IE = 0;  //Reset interrupt flag
        while(!IEC0bits.T1IE);// Wait here for timeout
        delay--;
    }

}
void init_Processor(void)
{

  /* uart1 Tx and Rx pin setup */ 
    RPINR18bits.U1RXR = 7;      //portB RB7 RX pin
    RPOR4bits.RP8R   = 3;       //portB RB8 TX  pin
 /* uart2 tx and rx pin setup */    
    RPINR19bits.U2RXR = 14;     //portB RB14 RX pin
    RPOR6bits.RP13R   = 5;      //portB RB13 TX pin
 /* uart3 tx and rx pin setup */    
    RPINR17bits.U3RXR = 10;     //portB RB10 RX pin
    RPOR5bits.RP11R   = 19;     //portB RB11 TX pin
    //Congifure analog and digital 
    ANSA = 0x0003;                                                  
    ANSB = 0x0000;
    PORTA = 0x0000;                                                 
    TRISA = 0X001B;                                                 
    PORTB = 0x0000;                                                 
    TRISB = 0x4680;
    // Init UART1
    U1MODE = 0x8000;                                                 
    U1STA = 0x3400;
    U1BRG = 25;                                                     
    // Init UART2
    U2MODE = 0x8000;                                                
    U2STA = 0x3400;
    U2BRG = 25;                                                     
    // Init UART3
    U3MODE = 0x8000;                                                
    U3STA = 0x3400;
    U3BRG = 25;
    IFS5bits.U3RXIF   = 0;            
    IEC5bits.U3RXIE   = 1;            
    U3MODEbits.UARTEN = 1;            
    U3STAbits.UTXEN   = 1;
    // Init ADC
    Timer1DelaymsInit();
    GSMPwrkey=1;    
}

Best Answer

I will share at least my experience with microchip, peripheral pin select and the UART maybe it will help you solve the problem. (cannot comment due to lack of reputation)

I once started programming on a dsPIC33F microcontroller with PPS. I thought that every pin was selectable for the UART. Well.. It turned out not to be the case. It took me a few days to find the problem in my system but eventually I found out that not every pin can have every function.

Tip: Change your pins and look very carefully if you have set every register accordingly to your application. Some registers have some kind of priority.

If I remember correctly the function closest to the microcontroller (pin diagram in datasheet) has the highest priority if two functions are set on the same pin.

Hope this helps.