PIC32MZ UART Baud Rate

Moderator: Benj

Post Reply
Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

PIC32MZ UART Baud Rate

Post by Brendan »

I'm coding embedded test code for a PIC32MZ2048EFG144 and have discovered that the Baud setting in the UART component must be set to precisely double the required Baud rate for comms to work, otherwise the usual garbled chars.

In a C block I've attempted to force changes to PBCLK2 prescaler (PB2DIVbits.PBDIV=0) to no effect whatsoever - but that could well be just me overlooking a lock bit somewhere.

Ordinarily, doubling the declared Baud rate in the component would be okay for a simple host comms workaround, but I'm also facing another issue - the need to invoke IrDA (UxMODEbits.IREN=1).

From purely a baud rate perspective I'm sure the same workaround given above will also fix IrDA data speed, but I'm also concerned about standard IrDA pulse timings and whether the root cause for this anomaly must first be addressed for IrDA to function.

Help and/or workarounds greatly appreciated (thanks).

Brendan

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Benj »

Hello Brendan,

This is something I am aware of however it seems that some MZ devices work correctly whereas some have half speed UART bauds. Therefore it's not something we can easily fix e.g. we fix some devices but break others that used to work fine.

It may even be a silicone revision issue however I'm not 100% on this as it could also easily be me overlooking something.

If you do make any progress on this then I would be very interested as it's a problem that has gone on for a fair while now.

I'm happy to make changes based on specific chips and as we discover new chips with the problem we can add e.g. a definition in the FCD file to work around the problem.

The current baud rate calculation is like this.

Code: Select all

#define MX_HARD_BAUD_X	(( MX_CLK_SPEED / MX_UART_BAUD_X ) / 4)
but some devices seem to need this instead.

Code: Select all

#define MX_HARD_BAUD_X	(( MX_CLK_SPEED / MX_UART_BAUD_X ) / 2)

Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Brendan »

Thank you Ben - Entirely appreciated.

Aware of three 'A' silicon versions and one 'B' version, I can confirm from what I'm coding that this particular issue manifests with ver. A3 silicon (assuming all A3 is equal!). The trouble is that when designing MCUs into products you really don't want to be re-coding, subject to indeterminate variables in supply chain and stock, and inclined to suspect your experiences are rooted in immature variants.

However, I'm also now able to confirm working IrDA channels by simply setting the IrDA enable bit following initialisation with the UART component, whilst preserving custom double-speed baud rate declaration in simple workaround.

Best regards,
Brendan

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Benj »

Hello,

Right as a bit of an experiment I have made a minor change to the CAL C code and added a new baud divider for all PIC32 MZ EF devices.

These updated files are now available via the Flowcode 8 update system.

If you give them a go then let me know how you get on. Hopefully no more having to double up the baud rate :D and PWM should also work fine.

Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Brendan »

That's fantastic - Thanks Ben :!: :D :D :D

I'm currently between working from home and supporting contractors identifying/fixing an underground water leak, so may take a while but will certainly post back with results from boards fitted with PICs exibiting this issue.

Best regards,
Brendan

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by stefan.erni »

Hi Ben

Thank you for the update. Would you be able to make synonymous for the PIC32MZ2048ECG100? My first prototype boards have this on it. Also there is an update that does not work. Maybe a folder that is missing


update.PNG
(9.5 KiB) Downloaded 2120 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Benj »

Would you be able to make synonymous for the PIC32MZ2048ECG100?
I can indeed. Should be up there now. If this works ok then I might roll out the mod to the EC family too?
Also there is an update that does not work. Maybe a folder that is missing
That file should not have been released just yet, sorry about that. We have now removed it from the system.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by stefan.erni »

Hi Ben


HHHmmm I think it's worst now. It's a quarter of the speed now.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by Benj »

Ok thanks that's very helpful. I've now changed the "PIC32MZ2048ECG100" to go the other way and divide by 8.

I'll wait to hear on the EF devices as I'm fairly sure divide by 2 should be correct for these but of course I could be wrong.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by stefan.erni »

Hi Ben

Perfect!

Now 115200 are equal to FC8 and Terminalprogram

speed115k.PNG
(100.9 KiB) Downloaded 2102 times


2.000.000Bd are working!
That's a good speed....
speed2m.PNG
(98.96 KiB) Downloaded 2102 times



The Clock from the PIC is 200Mhz


Speed_200Mega.PNG
(11.31 KiB) Downloaded 2102 times

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: PIC32MZ UART Baud Rate

Post by stefan.erni »

Hi Ben

I also tested Uart in softwaremode. It looks like the Uart is running twice as fast there.
speed_software.PNG
(108.04 KiB) Downloaded 2091 times

Post Reply