Problem initializing some GPIO pins but not others

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem initializing some GPIO pins but not others

ソリューションへジャンプ
2,671件の閲覧回数
cmarslett
Contributor I

I have taken the "Hello" sample code from the cookbook file and attempted to modify it to read 5 adjacent GPIO pins on the S32K144EVB-Q100 devkit.

Here is the initialization code I am using:

WDOG_disable();

* Enable clocks to peripherals (PORT modules) */
PCC-> PCCn[PCC_PORTA_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT A */
PCC-> PCCn[PCC_PORTB_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT B */
PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT C */
PCC-> PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT D */
PCC-> PCCn[PCC_PORTE_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT E */

/* Configure port E9 as GPIO input (BTN 0 [SW2] on EVB) */
PTE->PIDR &= ~(1L<<9); /* Port E9: Input enable for pin 9 */
PTE->PDDR &= ~(1L<<9); /* Port E9: Data Direction=input for pin 9 */
PORTE->PCR[9] = 0x00000113L; /* Port E9: MUX = GPIO, input filter enabled, pulled up */

PTC->PIDR &= ~(1L<<5 | 1L<<4); /* Port C: Input enable for pins 5 and 4 */
PTC->PDDR &= ~(1L<<5 | 1L<<4); /* Port C: Data Direction=input for pins 5 and 4 */
/* Configure port C5 as GPIO input (BTN 0 [SW2] on EVB) */
PORTC->PCR[5] = 0x00000113L; /* Port C5: MUX = GPIO, input filter enabled, pulled up */
/* Configure port C4 as GPIO input (BTN 0 [SW2] on EVB) */
// This register setup fails (note that pin 5's setup worked)
PORTC->PCR[4] = 0x00000113L; /* Port C4: MUX = GPIO, input filter enabled, pulled up */

PTA->PIDR &= ~(1L<<10 | 1L<<4);
PTA->PDDR &= ~(1L<<10 | 1L<<4);
/* Configure port A10 as GPIO input (BTN 0 [SW2] on EVB) */
PORTA->PCR[10] = 0x00000113L; /* Port A10: MUX = GPIO, input filter enabled, pulled up */
/* Configure port A4 as GPIO input (BTN 0 [SW2] on EVB) */
// This register setup fails (note that pin 10's setup worked)
PORTA->PCR[4] = 0x00000113L; /* Port A4: MUX = GPIO, input filter enabled, pulled up */

The double slash comments above indicate the lines that generate bus faults (I've tried both the default -O1 and -O0 optimization levels, with no noticeable difference).

The lines of code I use to read the GPIO pins look like this:

if ((PTE->PDIR & (1<<9)) == 0) { /* If GPIO Input is 0, DOWN pushed) */

I am missing something in the initialization here.  Any advice?

0 件の賞賛
返信
1 解決策
2,657件の閲覧回数
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi cmarslett,

PTA4 and PTC4 are default as debug port(JTAG\SWD). 

It is not recommended to modify the debugging port to GPIO, which will cause difficulties in debugging in the future.

PTA4 PTC4.jpg

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 件の賞賛
返信
1 返信
2,658件の閲覧回数
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi cmarslett,

PTA4 and PTC4 are default as debug port(JTAG\SWD). 

It is not recommended to modify the debugging port to GPIO, which will cause difficulties in debugging in the future.

PTA4 PTC4.jpg

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 件の賞賛
返信