KL02 NMI pin assign issue

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

KL02 NMI pin assign issue

跳至解决方案
1,930 次查看
kriske
Contributor II

When I use below code to assign NMI pin to GPIO, it can't assign successful.

 

PORTB_PCR5 |= PORT_PCR_MUX(1);

 

174452_174452.png001.png

 

But If I use below code, it can assign successful.

PORTB_PCR5 = (uint32_t)((PORTB_PCR5 & (uint32_t)~(uint32_t)

                            ( PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x06) ))

                            | (uint32_t)( PORT_PCR_MUX(0x01) ));

 

 

 

174454_174454.png002.png

 

 

Why I must need to clear PORT PCR ISF and set it to MUX 6 first and only in this way can the assign to GPIO(MUX 1) succeed.

 

标签 (1)
标记 (3)
0 项奖励
回复
1 解答
1,765 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Kris,

The default data of PORTB_PCR5 ->MUX is 011 :

pastedImage_1.png

So if you simple use PORTB_PCR5 |= PORT_PCR_MUX(1);  the MUX still "011".

We need first clear it , then set it to "001".

Please pay attention that in your code, there is a  negation ,

pastedImage_2.png

(PORTB_PCR5 & (uint32_t)~(uint32_t)PORT_PCR_MUX(0x06))  this code is clear the [9:8] of PORTB_PCR5 .

In a word , if you do not care about the interrupt status flag, you can only use the below code to configure PTB5 to GPIO function :

 PORTB_PCR5 = (uint32_t)((PORTB_PCR5 & (uint32_t)~(uint32_t)( 
                PORT_PCR_MUX(0x06)
               )) | (uint32_t)(
                PORT_PCR_MUX(0x01)
                ));

Hope it helps


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,765 次查看
kriske
Contributor II

Two questions are as follows,

 I want to confirm a GPIO read function, the PCR MUX is designated as other functions (such as I2C, TPM, UART), Then the GPIO's PDIR can also read the voltage of the pin?

The following example, The KL02 NMI pin must be cleared to 0 before setting to GPIO, So the question is we currently PTA4 MUX is set in the NMI, then I also use PDIR to read its potential?

Kris

0 项奖励
回复
1,765 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Kris,

1. At the same time one pin only can configured as only one function. So i think the first question is no,

while you can make a simple code to have a test by yourself.

2. Sorry for i don't know clearly the second one, the most GPIO operate code is simple,

so i think you only need write a simple code,  you can get the answer by yourself .

BR

Alice

0 项奖励
回复
1,765 次查看
kriske
Contributor II

Ok, I am finish test, If I assign it to digital peripheral module, it can detect voltage, but if I assign it to analog peripheral module, it don't any action.

0 项奖励
回复
1,766 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Kris,

The default data of PORTB_PCR5 ->MUX is 011 :

pastedImage_1.png

So if you simple use PORTB_PCR5 |= PORT_PCR_MUX(1);  the MUX still "011".

We need first clear it , then set it to "001".

Please pay attention that in your code, there is a  negation ,

pastedImage_2.png

(PORTB_PCR5 & (uint32_t)~(uint32_t)PORT_PCR_MUX(0x06))  this code is clear the [9:8] of PORTB_PCR5 .

In a word , if you do not care about the interrupt status flag, you can only use the below code to configure PTB5 to GPIO function :

 PORTB_PCR5 = (uint32_t)((PORTB_PCR5 & (uint32_t)~(uint32_t)( 
                PORT_PCR_MUX(0x06)
               )) | (uint32_t)(
                PORT_PCR_MUX(0x01)
                ));

Hope it helps


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复