How can I use a push button with FRDM_KL02Z and KSDK 2.0?

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

How can I use a push button with FRDM_KL02Z and KSDK 2.0?

Jump to solution
938 Views
natethompson
Contributor I

I am just getting started with the FRDM_KL02Z and the Kinetis SDK 2.0 using Kinetis design studio. I am just learning how to use the different peripherals starting with standard GPIO. I got the GPIO LED output demo from KSDK 2.0 working. Now I want to modify it so that when I hook up a push button to GPIO B8 and press it then the LED will flash and when it is not pressed it continues with whichever state it last entered (LED on or LED off). 

 

I also want to use the the internal pullup resistor on GPIO B8 so I don't have to hook one up externally. I created the relevant circuit and modified two files (included) to test this functionality.

 

In a nutshell it isn't working. Even with nothing hooked up to GPIO B8 (except the internal pullup resistor), the value I get from

GPIO_ReadPinInput(GPIO_BTN, 1u << GPIO_BTN_PIN);

is 0. This leads me to believe that I didn't set up the internal pullup resistor correctly. If I read the datasheet correctly, the KL02Z microcontroller only allows pullup resistors on most of the GPIO's, but that is what I want and I thought I enabled it correctly. I appear to have done something wrong. Second even if I connect GPIO B8 directly to 3V3 (with 10k resistor to prevent shorting) I still get 0 from the call above. This leads me to believe that my call to GPIO_ReadPinInput is not working. 

 

It's a bit embarassing that I can't get something as simple as polling GPIO input working, so please be patient with a new Kinetis developer.

 

Edit 1: I added the folder containing the entire project. I realized that this would make it easier for others to help me.

Original Attachment has been moved to: led_output.zip

Labels (1)
Tags (1)
1 Solution
608 Views
DavidS
NXP Employee
NXP Employee

Hi Nate,

Change line 95 to following:

btnValue = GPIO_ReadPinInput(GPIO_BTN, GPIO_BTN_PIN); //DES was 1u << GPIO_BTN_PIN);

Regards,

David 

View solution in original post

2 Replies
609 Views
DavidS
NXP Employee
NXP Employee

Hi Nate,

Change line 95 to following:

btnValue = GPIO_ReadPinInput(GPIO_BTN, GPIO_BTN_PIN); //DES was 1u << GPIO_BTN_PIN);

Regards,

David 

608 Views
natethompson
Contributor I

I knew it would be a stupid oversight on my part. A lot of the functions ask for a bitmask, but this one asks for an integer corresponding to the pin. Thanks for the help.

0 Kudos