PIC32MZ UART Configuration Problems - Solved !

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
Brendan
Posts: 232
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Contact:

PIC32MZ UART Configuration Problems - Solved !

Post by Brendan »

Hello All.

Working on a project with PIC32MZ2048EFG144 and really struggling with getting the UART to stream anything other than garbled characters, and given former comments and problems regarding the PIC32MZ, I wanted to share what I have found to work without issue. I have not invoked flow control in my particular case.

The following should be created in Flowcode's C component, only to replace the standard component call to initialise the UART. Then, simply add the UART component to the dashboard in the usual way, ensure that the settings in the parameter window precisely agree with the initialisation settings declared in the C component, then you can simply use the UART component to send and receive data in the conventional manner.

Unfortunately busy schedules severely limit my abilities to support and answer questions, though further detailed information is provided in the embedded link that respectfully credits the author of the blog that describes and presented these settings, and plenty of experts in this lively forum with more embedded experience than myself. I would add however that the sequence by which some of these settings are made is critical.

I hope this helps :wink:

Best regards,
Brendan

/*
************************************************************************
PIC32MZ UART Config Example
Credit: Adrian Mocke
https://www.aidanmocke.com/blog/2018/08/29/uart/
************************************************************************
Example settings: UART Channel 1, 115.2kbps, D7=TxD, G1=RxD
*/

U1RXR = 0b1100; // Rx on G1
TRISGbits.TRISG1 = 1; // Set G1 as input pin
RPD7R = 0b0001; // Set D7 as ch.1 TxD pin
U1MODE = 0; // Set UART 1 off prior to setting it up
U1MODEbits.BRGH = 0; // Standard speed mode (i.e. <1.5Mbps)
U1BRG = 100000000 / (16 * 115200) - 1;// This is the formula straight from the datasheet (assumes PBCLK#2 = 100MHz)
U1STA = 0; // Disable the TX and RX pins, clear all flags
U1STAbits.UTXEN = 1; // Enable the TX pin
U1STAbits.URXEN = 1; // Enable the RX pin
U1MODEbits.PDSEL = 0; // PDSEL controls how many data bits and how many parity bits we want, this is the default of 8-bit data, no parity bits that most terminals use
U1MODEbits.STSEL = 0; // STSEL controls how many stop bits used.
U1MODEbits.ON = 1; // Turn on the UART 1 peripheral

Post Reply