Trouble reading some Port C input pins on K64 using PE and sdk 1.3

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

Trouble reading some Port C input pins on K64 using PE and sdk 1.3

890 Views
inorman
Contributor III

I'm scratching my head trying to read an 8 pin dip switch connected to port pins PTC12 through to PTC19. I can only successfully read the status correctly of the one connected to PTC19. All the others only show as high if I have the pull-up enabled, and low if the pull-up is disabled no matter the state of the switch.

I've configured the pins in pin_mux to have the gpio function enabled with pull-up enabled as below

pin_mux setup.jpg

and then setup as input in the gpio component. 

gpiosetup.jpg

And then in my code i'm calling the function GPIO_DRV_ReadPinInput to read the state of each pin and outputting the result to the console.

state2=0;
state2=GPIO_DRV_ReadPinInput(CONFIG2); //check switches first
if (debug==1)
   PRINTF("\r\nstate2 %x\r\n", state2);

I've checked the default state of these pins in the datasheet, but see they default to disabled. Could anything else be interfering with there setup as input? Odd the one PTC19 is working fine while the others PTC12 to PTC18 are not. 

Kind regards

Ian

Tags (2)
0 Kudos
Reply
4 Replies

734 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Ian,

KDS's Processor Expert is a bit confusing I must to say. So please look at this picture:

kds_openclock1.png

There are some steps you must to do:

1. Set pin mux, and maybe pullup if it is needed;

2. Open the clock. The corresponding function is CLOCK_SYS_EnablePortClock();

3. Leave the pin in input mode;

4. Each time you modified in Processor Expert, you'd better push the "generate Processor Expert code" button.

Good Luck

0 Kudos
Reply

734 Views
inorman
Contributor III

Thanks for the pointer, I wasn't using Init_GPIO just fsl_gpio and pin_mux. I've added Init_GPIO and enabled the clock gate as you've shown however it hasn't made a difference. Anything else that could have an effect?

The pin_mux.c file seems to be generated correctly as it has the following.

/* Affects PORTC_PCR12 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,12UL,false);
PORT_HAL_SetMuxMode(PORTC,12UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,12UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,12UL,true);
/* Affects PORTC_PCR13 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,13UL,false);
PORT_HAL_SetMuxMode(PORTC,13UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,13UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,13UL,true);
/* Affects PORTC_PCR14 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,14UL,false);
PORT_HAL_SetMuxMode(PORTC,14UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,14UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,14UL,true);
/* Affects PORTC_PCR15 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,15UL,false);
PORT_HAL_SetMuxMode(PORTC,15UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,15UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,15UL,true);
/* Affects PORTC_PCR16 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,16UL,false);
PORT_HAL_SetMuxMode(PORTC,16UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,16UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,16UL,true);
/* Affects PORTC_PCR17 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,17UL,false);
PORT_HAL_SetMuxMode(PORTC,17UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,17UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,17UL,true);
/* Affects PORTC_PCR18 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,18UL,false);
PORT_HAL_SetMuxMode(PORTC,18UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,18UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,18UL,true);
/* Affects PORTC_PCR19 register */
PORT_HAL_SetPassiveFilterCmd(PORTC,19UL,false);
PORT_HAL_SetMuxMode(PORTC,19UL,kPortMuxAsGpio);
PORT_HAL_SetPullMode(PORTC,19UL,kPortPullUp);
PORT_HAL_SetPullCmd(PORTC,19UL,true);

0 Kudos
Reply

734 Views
inorman
Contributor III

Hi, thanks for the response.

Unfortunately this is on a mature project we're adding features to, so moving to SDK2.2 and MCUXpresso isn't an option.

As PTC19 is working fine I would believe so, where would this be set though as I can't see an enable etc in PE?

0 Kudos
Reply

734 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Ian,

have you enabled PTC's clock?

More, SDK1.3 is the old version. Why don't move to SDK2.2 and MCUXpresso? The tools is more friendly.

Regards

0 Kudos
Reply