PORT Control issue on FRDM-KL46Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PORT Control issue on FRDM-KL46Z

1,663 Views
StanoR
Contributor I

Hello,

I want to set the PORTA1 and PORTA2 pins as communication pins for UART0. 

I use code:

PORTA_PCR1 |= PORT_PCR_MUX(2);
PORTA_PCR2 |= PORT_PCR_MUX(3);

or:

PORTA_PCR14 |= PORT_PCR_MUX(3);
PORTA_PCR15 |= PORT_PCR_MUX(3);

The debug result is unexpected interrupt as showed on snapshot:

StanoR_0-1639693180211.png

When I use other than PORTA, e.g. PORTE, there is no issue.

Why PORTA causes issue and how to solve it?

Thanks,

Stano.

0 Kudos
Reply
7 Replies

1,642 Views
bobpaddock
Senior Contributor III

Do not use OR (|=) use assignment (=) when setting up the port registers.

This is a common mistake in NXP's examples, which usually causes no problems other than wasting a bit of processor time and/or code space.

In your case PORTA may have something already in it and ORing in the new value causes an unexpected outcome.

 

0 Kudos
Reply

1,635 Views
StanoR
Contributor I

Thank you for your comment, but the OR (|=) is not problem. I tried equal (=) instead and the result is the same.

I tried :

PORTA_PCR1 = PORTA_PCR1 | 0x00000200;

also and result is the same - fail. It is sufficient replace "A" with "E" and all is OK.

When I use such command and PORTis used, the issue arrives. When the other port e.g. PORT used, all is OK. 

I use the CodeWarrior 11.1, Build Id:181224.

0 Kudos
Reply

1,631 Views
bobpaddock
Senior Contributor III

"I use the CodeWarrior 11.1, Build Id:181224."

That is very old, is there a reason not to use the newer supported tools?

While not likely there could be a bad definition for the KL46 PORTA in an old tool.

Seems like we need to see more of your code.
The order things are done in is important.
Is there a default handler assigned for the UART?
That it is ending up in the default handler when PORTA is fiddled with doesn't necessary mean that the problem is PORTA.  It maybe jumping to an unassigned UART vector when  enabling that feature of PORTA.

A tedious way to find out is to assign a handler to everything and find out which one is being activated.

Also interrupts should be disabled when configuring things.

 

0 Kudos
Reply

1,657 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Stano,

Did you enable the clock gate of PORTA? SIM_SCGC5[PORTA] 
Maybe the clock gate of PORTE was enabled somewhere.
For Kinetis MCU development, it is recommended to use the latest MCUXpresso IDE and SDK.

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

1,649 Views
StanoR
Contributor I

Hi Robin,

yes, the clocks for PORTA are enabled. I tried many variants, but PORTA differs. Other ports function well.

Thank you for your recommendation, I will check it. 

But I would like to understand the core of issue - why the write instruction to PORTA_CR differs from the same instruction for other ports in MCU. I want to know "how it works" and where is the difference. Where it is described?

Thanks,

Stano.

0 Kudos
Reply

1,621 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

The value of PORTA_PCR are all 0x80008000 seems strange. And please check the register value of SIM_SCGC5[PORTA].

In addition you can use Processor Expert by refer to: Tutorial: printf() and “Hello World!” with the Freedom KL25Z Board

0 Kudos
Reply

1,615 Views
StanoR
Contributor I

Thank you all for suggestions.

Issue is solved, it was caused by stupid mistake in port clock settings.

Stano.

0 Kudos
Reply