PIC32MZ UART Baud Rate
Moderator: Benj
-
- 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
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
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
LinkedIn Profile...
http://www.linkedin.com/in/brendantownsend
http://www.linkedin.com/in/brendantownsend
- 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
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.
but some devices seem to need this instead.
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)
Code: Select all
#define MX_HARD_BAUD_X (( MX_CLK_SPEED / MX_UART_BAUD_X ) / 2)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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
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
LinkedIn Profile...
http://www.linkedin.com/in/brendantownsend
http://www.linkedin.com/in/brendantownsend
- 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
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 and PWM should also work fine.
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 and PWM should also work fine.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
That's fantastic - Thanks Ben
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
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
LinkedIn Profile...
http://www.linkedin.com/in/brendantownsend
http://www.linkedin.com/in/brendantownsend
-
- 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
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
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
- 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
I can indeed. Should be up there now. If this works ok then I might roll out the mod to the EC family too?Would you be able to make synonymous for the PIC32MZ2048ECG100?
That file should not have been released just yet, sorry about that. We have now removed it from the system.Also there is an update that does not work. Maybe a folder that is missing
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 654
- Joined: Fri Aug 19, 2016 2:09 pm
- Location: switzerland
- Has thanked: 182 times
- Been thanked: 179 times
- Contact:
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Hi Ben
Perfect!
Now 115200 are equal to FC8 and Terminalprogram
2.000.000Bd are working!
That's a good speed....
The Clock from the PIC is 200Mhz
Perfect!
Now 115200 are equal to FC8 and Terminalprogram
2.000.000Bd are working!
That's a good speed....
The Clock from the PIC is 200Mhz
-
- 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
Hi Ben
I also tested Uart in softwaremode. It looks like the Uart is running twice as fast there.
I also tested Uart in softwaremode. It looks like the Uart is running twice as fast there.