How to Use Built in Button in IMX RT 1010

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

How to Use Built in Button in IMX RT 1010

980 Views
abecohen73
Contributor I

Hello Everyone, 

I recently bought the IMX RT 1010 dev kit. I am trying to learn how to use this environment using a simple button-led project. Basically, when the button is pressed the LED goes off. 

However, I have no idea how to access the button output. 

The question is, I suppose, is:
1) How to access whether the button is pressed down or not. 
2) How to connect #1 to the LED. 

Here is the code so far:

#include "board.h"
#include "fsl_gpio.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_LED_GPIO BOARD_USER_LED_GPIO
#define EXAMPLE_LED_GPIO_PIN BOARD_USER_LED_GPIO_PIN
#define BUTTON BOARD_USER_BUTTON_GPIO
#define BUTTON_PIN BOARD_USER_BUTTON_GPIO_PIN


/*******************************************************************************
* Prototypes
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/
volatile uint32_t g_systickCounter;
/* The PIN status */
volatile bool g_pinSet = false;

/*******************************************************************************
* Code
******************************************************************************/
void SysTick_Handler(void)
{
if (g_systickCounter != 0U)
{
g_systickCounter--;
}
}

void SysTick_DelayTicks(uint32_t n)
{
g_systickCounter = n;
while (g_systickCounter != 0U)
{
}
}

/*!
* @brief Main function
*/
int main(void)
{
/* Board pin init */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();


//init button
struct _gpio_pin_config *Config = {0};
Config->direction = kGPIO_DigitalOutput;
Config->interruptMode = kGPIO_IntHighLevel;
GPIO_PinInit(BUTTON, BUTTON_PIN, Config);

/* Set systick reload value to generate 1ms interrupt */
if (SysTick_Config(SystemCoreClock / 1000U))
{
while (1)
{
}
}

while (1)
{

//READ BUTTON STATUS
volatile uint32_t button_status = GPIO_PinRead(BUTTON, BUTTON_PIN);
bool button_bool = button_status != 0u;

/* Delay 1000 ms */
SysTick_DelayTicks(1000U);

if(button_bool)
{
GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);
}
}
}

Once again, I appreciate everyone's help!

Labels (1)
0 Kudos
Reply
1 Reply

869 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abraham Cohen,

    Please refer to the RT1010 SDK:

SDK_2.6.0_EVK-MIMXRT1010\boards\evkmimxrt1010\driver_examples\gpio\input_interrupt

   Which can be downloaded from this link:

   Welcome | MCUXpresso SDK Builder 

    pastedImage_2.png

  If you want to change the LED status, you can add your LED output code in the yellow part in the above picture.

  About the LED code, you can refer to the SDK code:

   SDK_2.6.0_EVK-MIMXRT1010\boards\evkmimxrt1010\driver_examples\gpio\led_output

Wish it helps you!

If you still have questions about it, please kindly let me know.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
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 Kudos
Reply