PIC32MX using both serial ports UART1 and UART2

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
celsoscomparim
Posts: 15
Joined: 24 Jan 2009 12:46
Location: BRASIL - Boituva - SP

PIC32MX using both serial ports UART1 and UART2

#1 Post by celsoscomparim » 02 Jan 2017 15:06

Hello, happy new year,
I'm trying to use both serial ports UART1 and 2 at the "same time" in the microcontroller PIC32MX150F128B, but only UART1 work OK, the UART2 didn't work.
When I configure UART1 or UART2 individualy, works fine, but if I configure both, as the code below, UART2 doesn't work.

Please, could you help me?

Code: Select all

void main() {
   JTAGEN_bit = 0;
   ANSELA = 0;
   ANSELB = 0;
   TRISA = 0;
   TRISB = 0;
   LATA = 0;
   LATB = 0;

   Unlock_IOLOCK();
   PPS_Mapping(_RPB3, _OUTPUT, _U1TX);
   PPS_Mapping(_RPB2, _INPUT, _U1RX);
   PPS_Mapping(_RPB10, _OUTPUT, _U2TX);
   PPS_Mapping(_RPB11, _INPUT, _U2RX);
   Lock_IOLOCK();
   
   I2C1_Init(100000);
   UART1_Init(115200);
   UART2_Init(115200);
   delay_ms(100);
   while(1){
      UART1_Write(0xCD);
      UART2_Write(0xAB);
      delay_ms(250);
   }
}

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: PIC32MX using both serial ports UART1 and UART2

#2 Post by Aleksandar.Mitrovic » 04 Jan 2017 10:46

Hi,

Did you try to use UART_Set_Active?

Kind regards,
Aleksandar

celsoscomparim
Posts: 15
Joined: 24 Jan 2009 12:46
Location: BRASIL - Boituva - SP

Re: PIC32MX using both serial ports UART1 and UART2

#3 Post by celsoscomparim » 05 Jan 2017 17:41

Hi, thanks for the answer!

Yes, I tried.

The problem is in the MikroC library, because if I replace:

Code: Select all

   Unlock_IOLOCK();
   PPS_Mapping(_RPB3, _OUTPUT, _U1TX);
   PPS_Mapping(_RPB2, _INPUT, _U1RX);
   PPS_Mapping(_RPB10, _OUTPUT, _U2TX);
   PPS_Mapping(_RPB11, _INPUT, _U2RX);
   Lock_IOLOCK();
By:

Code: Select all

trisb.f2=1; trisb.f11=1;
   U1RXR = 0b00000100;
   U2RXR = 0b00000011;
   RPB3R = 0b00000001;
   RPB10R = 0b00000010;
Both UARTs works Ok.
Am I right?

Thanks.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: PIC32MX using both serial ports UART1 and UART2

#4 Post by Aleksandar.Mitrovic » 06 Jan 2017 11:31

Hi,

If you set in the Edit Project bits for PPS correctly you can try it like this:

Code: Select all

 Unlock_IOLOCK();
   PPS_Mapping(_RPB3, _OUTPUT, _U1TX);
   PPS_Mapping(_RPB2, _INPUT, _U1RX);
   PPS_Mapping(_RPB10, _OUTPUT, _U2TX);
   PPS_Mapping(_RPB11, _INPUT, _U2RX);
 Lock_IOLOCK();
   TRISB.F3 = 0;
   TRISB.F2 = 1; 
   TRISB.F10=0;
   TRISB.F11=1;
Note that at this moment we do not have this MCU for test, it will be good if you can do some test for us.
Therefore I suggest you to open ticket on our Help desk and we can start from there if this above do not work.
Is that OK with you?

Kind regards,
Aleksandar

Post Reply

Return to “mikroC PRO for PIC32 General”