Instruction for reading the state of a button

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

Instruction for reading the state of a button

672 Views
nikivendola
Contributor III

Hello everyone,
Below you can see the pattern of how the micro and connected MK10DN512ZVLL10 tab made by my university ...

pastedImage_0.png

Enabling the button highlighted in yellow?
How instruction can read their status?

Thanks in advance for any indicaizone

0 Kudos
2 Replies

429 Views
EarlOrlando
Senior Contributor II

Hello Niki,

Are you using KSDK or any RTOS?

If you are in baremetal it is very simple. Please see the answer in the post below to see how to manage the GPIO pins.

Re: Port configuration

Best regards,

Earl.

/* If this post answers your question please click the Correct answer ​button. */

0 Kudos

429 Views
mjbcswitzerland
Specialist V

Niki

Here is how to configure and read your input in the uTasker project:

#define BUTTON_SOS (PORTC_BIT16)

_CONFIG_PORT_INPUT_FAST_HIGH(C, BUTTON_SOS, PORT_PS_UP_ENABLE);

if (_READ_PORT_MASK(C, BUTTON_SOS) != 0) {

    fndDebugMsg("SOS is not pressed\n\r");

}

else {

    fndDebugMsg("SOS is pressed\n\r");

}

If you prefer to configure an interrupt to fire when the button is pressed, the following code does it:

INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters

interrupt_setup.int_type       = PORT_INTERRUPT; // identifier to configure port interrupt

interrupt_setup.int_handler    = fnButtonPressed; // handling function

interrupt_setup.int_priority   = 5; // interrupt priority level

interrupt_setup.int_port       = PORTC; // the port that the interrupt input is on

interrupt_setup.int_port_bits  = BUTTON_SOS;

interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON); // interrupt is to be falling edge sensitive

fnConfigureInterrupt((void *)&interrupt_setup); // configure interrupt

whereby the interrupt callback to handle the press is something like:

// Button interrupt handler

//

static void fnButtonPressed(void)

{

    fnInterruptMessage(BUTTON_TASK, E_BUTTON_PRESSED);

}

Why not add your board to the uTasker project so that you can simulate and test all operation and greaty accelerate your work with it?

Take a look at the following University board that was added to it in just a couple of hours (including SD card and USB operation):

µTasker Kinetis Capuccino-KL27 support

http://www.coffeebrain.org/blog/

Regards

Mark

Kinetis: µTasker Kinetis support

K60: µTasker Kinetis TWR-K60N512 support  / µTasker Kinetis TWR-K60D100M support  / µTasker Kinetis TWR-K60F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos