PIC32MZ1024 UART not working

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

PIC32MZ1024 UART not working

#1 Post by KriszAime » 31 Oct 2017 15:53

Hello Everyone.
For my Project purpose, i would like to use UART1 hardware in my PIC32MZ. But in the 'MZ' categ, there is only "PPS" (Peripheral Pin Select) funtctions to do so.

Here my code:

char uart_rd;

void main() {
ANSELB=0x0000;
Unlock_IOLOCK();

PPS_Mapping(_RPB14, _OUTPUT, _U1TX); // Sets pin PORTB.14 to be Output and maps UART1 Transmit to it
PPS_Mapping(_RPB3, _INPUT, _U1RX); // Sets pin PORTB.3 to be Input and maps UART1 Receive to it

Lock_IOLOCK();

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize

UART1_Write_Text("Start");
UART1_Write(13);
UART1_Write(10);

while (1) { // Endless loop

if (UART1_Data_Ready()) { // If data is received
uart_rd = UART1_Read(); // read the received data
UART1_Write(uart_rd); // and send data via UART
}
}


}

It's Just not working at all. Has no input data, and in the Tx Pin, there is no signal just ground.
Any idea?
I missd something?
or is it all bad?

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: PIC32MZ1024 UART not working

#2 Post by dusan.poluga » 01 Nov 2017 18:10

Hi,

Try using the PPS_Mapping_NoLock function instead like shown below.

Code: Select all

Unlock_IOLOCK();
PPS_Mapping_NoLock(_RPB14, _OUTPUT, _U1TX); // Sets pin PORTB.14 to be Output and maps UART1 Transmit to it
PPS_Mapping_NoLock(_RPB3, _INPUT, _U1RX); // Sets pin PORTB.3 to be Input and maps UART1 Receive to it
Lock_IOLOCK();
Also since you are using the PPS function you need to initialize the uart with this uart remappable function.

Code: Select all

 UART1_Remappable_Init(9600);
Best Regards,
Dusan Poluga.

KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

Re: PIC32MZ1024 UART not working

#3 Post by KriszAime » 02 Nov 2017 13:14

Thanks but,

The PIC32 PRO Compiler does not recognize the "Remappable" func. and keeps Saying:

Undeclared identifier 'UART1_Remappable_Init' in expression

I tick the "All include" in project, so i ain't know what header, or include file is missing for this. Or maybe, the 'PIC32MZ1024ECG100' different.

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: PIC32MZ1024 UART not working

#4 Post by dusan.poluga » 03 Nov 2017 18:54

Hi,
The PIC32 PRO Compiler does not recognize the "Remappable" func. and keeps Saying:

Undeclared identifier 'UART1_Remappable_Init' in expression
Yes you are absolutely correct this function does not exist for this micro controller.
It is my mistake for not asking you for the exact micro controller that you are using. I am sorry for that.

The PPS mapping should be correct.

Code: Select all

Unlock_IOLOCK();
PPS_Mapping_NoLock(_RPB14, _OUTPUT, _U1TX); // Sets pin PORTB.14 to be Output and maps UART1 Transmit to it
PPS_Mapping_NoLock(_RPB3, _INPUT, _U1RX); // Sets pin PORTB.3 to be Input and maps UART1 Receive to it
Lock_IOLOCK();
UART1_Init(9600);
Did you try replacing the PPS_Mapping functions with the PPS_Mapping_NoLock functions ?


Best Regards,
Dusan Poluga.

KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

Re: PIC32MZ1024 UART not working

#5 Post by KriszAime » 03 Nov 2017 21:04

The Compiler can recognize the "_nolock" version, but nothing has changed. There is no signal at the selected Tx pin either.

I tried with some another pins in the PPS but it seems not work at all.

As i know This Particular Microcontroller has no dedicated UART pins, it's only working with PPS. (unfortunate for me)

But when Initialize with the UART2_init(9600); then the Tx pin works!

Unfortunately, can send, but not receive! ( Rx pin? ) what a...

So, the question remains. Is there any example that shows how to initialize properly the UART for the "MZ1024" controller in mikroC 32?

Also, i had read the PDF Datasheet for the P32MZ1024ECG100 mentioning, some registers for PPS, but not quite sure what it is, or how it works.

steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

Re: PIC32MZ1024 UART not working

#6 Post by steve42lawson » 16 Jun 2020 18:27

I realize this is an old thread, but in case anyone else winds up here, looking for answers, I may have a couple:
  1. First of all, make sure, in the Edit Project dialog, you have "The PPSLOCK bit can be set and cleared repeatedly in software" set -- even if only temporarily for debugging purposes.
  2. I don't even bother with the MikroPro PPS library functions. I do the PPS assigns directly, like shown below:

Code: Select all

// In this case I'm using the PIC16F15344 -- but, the general case is similar
RX1DTPPS = 0b00001101;   // Assign UART RX1 input to RB5 [I use the binary notation so there's no ambiguity -- I mean, it's shown as binary in the datasheet, after all  :wink: ]
RC6PPS   = 0b00001111;   // Assign UART TX1 output to RC6
Consult the Microchip datasheet for whatever PIC you're using. You can find them on the Microchip website.
Humility is the lack of the desire to impress, not the lack of being impressive.

Post Reply

Return to “mikroC PRO for PIC32 General”