Both LED's

cancel
Showing results for 
Search instead for 
Did you mean: 

Both LED's

98 Views
GarageDirt
Contributor II

The MIMXRT1176 evk has two user LED's.  One on GPIO_AD_04 (green) and one on GPIO_AD_26(red). Is it possible to make both blink at the same time?    The reason I want to do this is because I just want to find out how to make multiple pins work not just one as shown in evkmimxrt1170_igpio_led_output_cm7.  Once I find this out, hopefully I can apply the knowledge to other (non-led) pins.  NXP documentation is pretty much useless in this area.

0 Kudos
3 Replies

59 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @GarageDirt 

  Check my attached mcuxpresso project, I already help you add the RED led: D34.

  I have tested it on my side, both yellow and red led is blinking.

  Code:

1. pinmux.c void BOARD_InitPins(void) {

IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_26_GPIO9_IO25, /* GPIO_AD_04 is configured as GPIO9_IO03 */
0U); /* Software Input On Field: Input Path is determined by functionality */

 

2. main

gpio_pin_config_t led_config1 = {kGPIO_DigitalOutput, 1, kGPIO_NoIntmode};

GPIO_PinInit(GPIO9, 25U, &led_config1);

GPIO_PortToggle(GPIO9, 1<<25U);

 

Wish it helps you!

Best Regards,

kerry

0 Kudos

90 Views
nickwallis
Contributor V

Yes, you can.

There are (at least) 2 ways of doing this.

(1), You could use the SDK functions and copy/adapt them to your needs. This should be pretty straightforward as you already have example code working.

(2), You can write directly to the GPIO registers, which is what I tend to do. For example, see below for an example using GPIO4 bit 12

To set the pin state to logic high : GPIO4->DR |= (1UL << 12)

To set the pin state to logic low : GPIO4->DR &= ~(1UL << 12)

To toggle the pin state : GPIO4->DR_TOGGLE |= (1UL << 12)

Obviously, you need to have correctly set the pins up beforehand for this to work as expected. (select GPIO function for the pin, and set the GPIO pin direction to output)

-Nick

 

0 Kudos

76 Views
GarageDirt
Contributor II

Hi Nick,

 

I can see that you are not on the nxp staff and may not have the time to answer this, but I am writing this in hopes that you can. 

 

In your response to my question about both LEDs turning on, you suggested I adapt the SDK function to accomplish the task.  Well, I tried that by taking the original code that works and adding lines of code that I think should be there for the red led. The original code works just fine.  The seven lines of code that I added are commented out using the form of "  //*****  " ahead of the line of non-functional code so that they are more easily spotted.  Additionally, I added  information to the ConfigTools (pins) for the red led as:

L14   GPIO_AD_26  , etc..

 

My question is...  can you take a quick look at my seven lines of added code and tell me where I am going astray?  I would  really appreciate any help you can offer.

 

 

#include "pin_mux.h"

#include "clock_config.h"

#include "board.h"

#include "fsl_debug_console.h"

#include "fsl_gpio.h"

 

/*******************************************************************************

 * Definitions

 ******************************************************************************/

#define EXAMPLE_LED_GPIO               BOARD_USER_LED_GPIO

#define EXAMPLE_LED_GPIO_PIN           BOARD_USER_LED_GPIO_PIN

//******#define EXAMPLE_REDLED_GPIO            BOARD_USER_REDLED_GPIO

//******#define EXAMPLE_REDLED_GPIO_PIN        BOARD_USER_REDLED_GPIO_PIN

 

 

 

/*******************************************************************************

 * Prototypes

 ******************************************************************************/

 

/*******************************************************************************

 * Variables

 ******************************************************************************/

/* The PIN status */

volatile bool g_pinSet = false;

/*******************************************************************************

 * Code

 ******************************************************************************/

/*!

 * @brief Main function

 */

int main(void)

{

 

 

    /* Define the init structure for the output LED pin*/

gpio_pin_config_t    led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

 

//****** gpio_redpin_config_t     pinL14_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

    /* Board pin, clock, debug console init */

    BOARD_ConfigMPU();

    BOARD_InitPins();

    BOARD_BootClockRUN();

    BOARD_InitDebugConsole();

 

    /* Print a note to terminal. */

    PRINTF("\r\n GPIO Driver example\r\n");

    PRINTF("\r\n The LED is blinking.\r\n");

 

    /* Init output LED GPIO. */

    GPIO_PinInit(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, &led_config);

//******    GPIO_PinInit(EXAMPLE_REDLED_GPIO, EXAMPLE_REDLED_GPIO_PIN, gpio_redpin_config_t );

 

    while (1)

    {

        SDK_DelayAtLeastUs(100000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);

#if (defined(FSL_FEATURE_IGPIO_HAS_DR_TOGGLE) && (FSL_FEATURE_IGPIO_HAS_DR_TOGGLE == 1))

          GPIO_PortToggle(EXAMPLE_LED_GPIO, 1u << EXAMPLE_LED_GPIO_PIN);

//******  GPIO_PortToggle(EXAMPLE_REDLED_GPIO, 1u << EXAMPLE_REDLED_GPIO_PIN);

 

#else

        if (g_pinSet)

        {

              GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 0U);

  //******   GPIO_PinWrite(EXAMPLE_REDLED_GPIO, EXAMPLE_REDLED_GPIO_PIN, 0U);

            g_pinSet = false;

        }

        else

        {

              GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);

 //******     GPIO_PinWrite(EXAMPLE_REDLED_GPIO, EXAMPLE_REDLED_GPIO_PIN, 1U);

            g_pinSet = true;

        }

#endif /* FSL_FEATURE_IGPIO_HAS_DR_TOGGLE */

 

0 Kudos