UART PIC32MX534F064H No RX or TX

An area to discuss 32-bit PIC specific problems and examples

Moderator: Benj

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

UART PIC32MX534F064H No RX or TX

Postby QMESAR » Fri Jun 02, 2017 10:13 am

Hi All,
I have configured the UART in the attached project @115200 baud rate however the Rx interrupt is never triggered.
I then just for testing write a char in the main loop however there is no activity on the UART Tx pin.
I have verified that there is activity on the RX pin from my PC data that I send to the PIC (the interrupt does not fire) it seems the UART is totally not working.

Please help to solve this issue :D

FC7.rar
(67.02 KiB) Downloaded 99 times
Attachments
1.JPG
(54.06 KiB) Not downloaded yet

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 10:48 am

Thanks for the info.
I'll have a quick look and see if I can see anything, but my PIC32 knowledge in next to zero :D

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Fri Jun 02, 2017 11:04 am

LeighM wrote:Thanks for the info.
I'll have a quick look and see if I can see anything, but my PIC32 knowledge in next to zero :D


You like the ARM controllers to much :D :D
Thanks Leigh appreciate this may be it me doing something wrong :oops:

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 11:09 am

Indeed I do :lol:

Could you try moving the InitMCU() to before the Interrupt Enables?
I think the UART init is turning the interrupt back off.
These users thanked the author LeighM for the post:
QMESAR (Fri Jun 02, 2017 2:14 pm)
Rating: 5.26%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Fri Jun 02, 2017 1:31 pm

I think the UART init is turning the interrupt back off.

Leigh I will do this later when I am back at my lab however this could be and would explain why the RX interrupt is not working but shouldn't the TX still work ? :?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Fri Jun 02, 2017 2:14 pm

Hi Leigh

The move of the initMCU() function indeed help to keep the RX interrupt enabled however I see the same problem as Zane here viewtopic.php?f=70&t=18939
Once the RX Interrupt fires the first time the main loop is not executed and even the Timer1 interrupt is not executed as my Led toggle in the Timer1 interrupt moves to about 300mSec end longer (my impression is that the code does not return from the Interrupt )
I also doubt that the Tx function is working
if you need scope traces let me know and I will make them

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 2:15 pm

Ooops, sorry, I only replied to your first point, missed the second, just like my bank manager :lol:
These users thanked the author LeighM for the post:
QMESAR (Fri Jun 02, 2017 2:24 pm)
Rating: 5.26%
 

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 2:23 pm

Right, and thanks for the reminder about the other post, yes looks like they are connected

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 3:00 pm

Could you please try with the attached FCD?
Thanks,
Leigh
32MX534F064H.fcdx
(43.44 KiB) Downloaded 94 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Fri Jun 02, 2017 4:05 pm

Leigh

Thank for the file unfortunately with me the same symptoms no TX and also the T1 interrupt is delayed to the RX interrupt time

Thanks for your efforts :D

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby LeighM » Fri Jun 02, 2017 4:12 pm

OK, thanks for trying it. Maybe I need to now concentrate on the Tx side, next week :wink:

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Tue Jun 13, 2017 10:57 am

Hello Peter,

I've applied Leigh's fix to all the PIC32 devices and hopefully this will help the situation.
PIC32.zip
(1.31 MiB) Downloaded 89 times


There is also a new CAL UART file here for the PIC32 which may also help.
viewtopic.php?f=70&t=18930#p82082

Let me know how you get on and I'll have a quick play with the PIC32 devices I have here.
These users thanked the author Benj for the post:
QMESAR (Tue Jun 13, 2017 4:31 pm)
Rating: 5.26%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Tue Jun 13, 2017 4:31 pm

Hi Ben
Thank you very much,I am out of my lab this week, I will try it next week and let you know how it went.
Have good one
These users thanked the author QMESAR for the post:
Benj (Tue Jun 13, 2017 4:52 pm)
Rating: 5.26%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Sun Jun 18, 2017 5:13 pm

Hi Ben.
I have tried the new files and the following is happening

(1) I have a LED blinking in the T1 interrupt which run exactly 1 sec
(2) I then write 2 chars from the UART no transmission at all no activity on the TX pin
(3) I then activate the UART RX interrupt and sent to the PIC32 2 chars result the moment that the UART Rx interrupt fires the T1 interrupt time change from 1sec to about 4 seconds and I also see no data in the RX buffer

just thought I let you know :D

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 10:06 am

Hello Peter,

Would you mind posting your project file and I will investigate the issue for you. Hopefully something simple.

I'm currently re-looking at the project you posted above.

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 10:50 am

It may also be worth testing just the UART functionality on this device without interrupts. It sounds to me like it's the UART that's having problems and not necessarily the associated interrupts.

Looking at the definition file there is only 5 UARTs defined but the datasheet is showing 6. Hmm.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Mon Jun 19, 2017 11:29 am

Hi Ben,

I will post the file I am just today at a customer location will probably be tomorrow or Wednesday,

Just as info there is a problem with the PIC32 interrupts ,I have had this issue in a normal C file project(MPLAB) and the work around is by enabling the interrupts every time in the interrupt with the highest priority with an assembly instruction
asm EI as for some reason the interrupts get disabled in the interrupt with the highest priority
for example if UART Interrupt is priority 7 and T1 is priority 6 then the UART the EI bit get cleared every time UART interrupt fires by enabling the Interrupts again in the ISR keeps it going and vise versa also will happen meaning if T1 is priority 7 and UART priority 6 the the Interrupts get disabled when T1 fires :D :D I dont want to point you in a wrong direction however it worth while to investigate this in FC

Question how is the priorities set in FC as I did not see any setting for the priorities ? or am I missing something ?

I also did try the UART just by Transmitting 2 chars with out interrupts and I have no activity on the PIC32 TX pin

Ben this is not serious don't loos to musch time on this as if I am the only one suffering with a UART problem

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 11:33 am

A number of this device family had UART definition issues,

The device you're using is missing UART channel 6 and some other devices had a duplicated channel 5?

Here is the current fixed definition file, but this doesn't explain why you're having problems with channel 2. Can you try transmitting from the various UART channels without interrupts and see if any of them are working.

32MX534F064H.fcdx
(43.23 KiB) Downloaded 75 times


I'm going to have a look at the CAL code now and see if I can spot anything incorrect or inconsistent for this family.

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 11:36 am

Looking at the definition file both timer and UARTs should have an interrupt priority of 1. I'm not aware of any problems here with priority but I will investigate.

It might also be nice to have a configuration option to allow the priority to be set which should be fairly simple.

For now let's focus on the UART not working.
These users thanked the author Benj for the post:
QMESAR (Mon Jun 19, 2017 12:55 pm)
Rating: 5.26%
 

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 12:04 pm

I've had another look through the CAL file and added the high speed / low speed baud rate detection that is in the other families.

This should hopefully make things slightly more reliable with slower baud rates combined with fast clock speeds but probably won't effect the faster baud rates.

Have a go with this latest version of the CAL file.

PIC32BIT_CAL_UART.c
(25.45 KiB) Downloaded 79 times


One thing I have noticed is that the UART enable bit is called "UARTEN" whereas the bit in the datasheet for this device is "ON". I've looked at the compiler definitions and it looks like both UARTEN and ON are valid. but this could be something to try.

So if your still getting no joy with any UART at various BAUD rates then try adding this code to a C icon after initialising the UART. Replace U1 with the number of your UART peripheral, e.g. U2 for UART channel 2.

Code: Select all

U1MODEbits.ON = 1;                     // Switch on serial interface
These users thanked the author Benj for the post:
QMESAR (Mon Jun 19, 2017 12:54 pm)
Rating: 5.26%
 

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 12:18 pm

One last thing you could try is to add an external or internal pull up resistor to the UART receive pin, Just to be sure that the chip isn't doing something "clever" like recognising a break and disabling the UART for you.
These users thanked the author Benj for the post:
QMESAR (Mon Jun 19, 2017 12:56 pm)
Rating: 5.26%
 

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

Re: UART PIC32MX534F064H No RX or TX

Postby Benj » Mon Jun 19, 2017 4:19 pm

As a quick test I've added priority options to all the interrupts in this definition file. They all should appear now in the interrupt enable properties.

I've had to get rid of the sub-priority option from the timer interrupts as it looks like Flowcode currently has a hard limit of 4 interrupt options. With the fifth option in place Flowcode currently crashes when loading the project. These timer sub priorities will default to 0 (Lowest). If it's needed then you can always add a C icon to set the sub priority after enabling the interrupt. Not ideal but will work around the problem for now.

32MX534F064H.fcdx
(57.79 KiB) Downloaded 74 times


I've put in a request for the limit to be increased to 5 or 6 but not sure if this will happen now for v7 as it might have knock on consequences.

If you have a go then let me know how you get on. If it looks good then I'll roll this out to the other PIC32 devices, and maybe other devices with interrupt priority control registers.
These users thanked the author Benj for the post (total 2):
QMESAR (Mon Jun 19, 2017 5:44 pm) • Zane (Wed Jun 21, 2017 2:03 am)
Rating: 10.53%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Mon Jun 19, 2017 5:43 pm

Ben

Thank you very much I will give this all ago and let you know thanks a million for your efforts I appreciate this :D
Have good evening.
These users thanked the author QMESAR for the post:
Benj (Mon Jun 19, 2017 6:02 pm)
Rating: 5.26%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1127
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 347 times
Been thanked: 555 times
Contact:

Re: UART PIC32MX534F064H No RX or TX

Postby QMESAR » Wed Jun 21, 2017 7:04 am

If you have a go then let me know how you get on. If it looks good then I'll roll this out to the other PIC32 devices, and maybe other devices with interrupt priority control registers.

Hello Ben.

I would not recommend doing this now ,I had a change last night to run the new files and I am sad to say not very successful.
(1) Attached is a simple project which Runs T1 Interrupt ,The interrupt only work when the priority is set at Lowest(1) if I use any other priority above 1 - 7 the interrupt does not fire at all( left the sub priority at 0
(2) I then removed the T1 interrupt and Used an UART2RX interrupt The UART is not responding at all ,No TX and NO RX polled or interrupt driven (Unfortunate on this board I can not try another UART port as the mcu is in a custom PCB which all the other pins are wired to some critical stuff.

My conclusion
The UART 2 is not reponding at all (regardles interrupts or polling)
The interrupt priorities is not working as we expect.

Please do not loose time on this issue with me I have to move on I will use the MCC tool set to complete this task and when I have time I will setup a test system to test these issues(specially if the other UART's are working)
I am under pressure to deliver this to my customer ,I have no choice, I have to use MPLAB as you were away and Leigh tried to help and in between is at least 3 weeks :D I am sorry about this but my customer is getting nervous and a bit aggressive with me :oops:

Thank again for your hard work I appreciate all very much
Attachments
BlinkLed_interrupt.rar
(37.11 KiB) Downloaded 60 times
These users thanked the author QMESAR for the post:
Benj (Wed Jun 21, 2017 10:14 am)
Rating: 5.26%