2
\$\begingroup\$

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;    
}
| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ You didn't get warnings for using the register names in your UART header even though you didn't include the PIC header file in there? \$\endgroup\$ – Funkyguy Sep 30 '15 at 13:51
  • \$\begingroup\$ Are we supposed to know what L80 and M95 modules are? Give some context.. \$\endgroup\$ – m.Alin Sep 30 '15 at 13:59
  • \$\begingroup\$ l80 is gps module and m95 is gsm module both are quectel product \$\endgroup\$ – arun Sep 30 '15 at 14:04
  • \$\begingroup\$ You probably forgot to set up the peripheral pin select. \$\endgroup\$ – Olin Lathrop Sep 30 '15 at 14:13
  • \$\begingroup\$ after some changes pps setting uart2 working and but uart3 not working \$\endgroup\$ – arun Sep 30 '15 at 14:39
1
\$\begingroup\$

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.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ You should note that what you are talking about are remappable output pins. Some mappable pins are only for inputs. These are clearly labeled as such by being called RPIxx instead of RPxx. Also, any number of peripherals can use the same pin as input. The only one peripheral rule only applies to output pins. Of course the way output pins are mapped prevents this anyway, since for mappable output pins, you write the peripheral function ID in a register for that pin. This whole PPS mechanism may seem complicated, but it makes sense when you think about it. \$\endgroup\$ – Olin Lathrop Sep 30 '15 at 14:17
  • \$\begingroup\$ Correct, but I once connected a single UART connection to a pin assigned by the PPS register and it didn't work. I did exactly the same thing with another pin and I had no problems at all. I really tried looking for a note somewhere in the datasheet that states that pin cannot be used for UART purposes or something like it but to no avail. I also contacted microchip about it, but their response didn't make much sense to me. I could use another pin so I had no difficulties, but beware of PPS. \$\endgroup\$ – Weaverworm Sep 30 '15 at 14:28
  • \$\begingroup\$ This sounds like you had some other problem. I don't believe that the UART output can't be assigned to any RPx pin, or the input to any RPIx or RPx pin. \$\endgroup\$ – Olin Lathrop Sep 30 '15 at 14:31
  • \$\begingroup\$ That may be, but it is strange that when I changed the pin it instantly worked. This means that whatever I did in my code (might be completely different than the PPS settings) did keep me from using the UART at those RPIx or RPx pins. Just indicating that the problems might be solved by changing pins. Nevertheless thank you for your comments :) \$\endgroup\$ – Weaverworm Oct 9 '15 at 7:39

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.