Search code examples
embeddedgpio

GPIO commands for Blinking LED problem in simplisity studio


I have the following commands

GPIO_PinOutClear(LED_PORT_E,15)
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0)
GPIO_PinOutSet(LED_PORT_E,15)

I know that I should put ON value delay OFF value in a loop in order to make the LEDs blink constantly. I have tried to implement it, but it's not working. Where did I go wrong?

#include <stdint.h>
#include <stdbool.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "bsp.h"
#include "bsp_trace.h"

#define LED_PORT_E    gpioPortE
#define LED_PIN_E     15

#define LED_PORT_A    gpioPortA
#define LED_PIN_A     15

volatile uint32_t msTicks; /* counts 1ms timeTicks */

void Delay(uint32_t dlyTicks);

/***************************************************************************//**
 * @brief SysTick_Handler
 * Interrupt Service Routine for system tick counter
 ******************************************************************************/
void SysTick_Handler(void)
{
  msTicks++;       /* increment counter necessary in Delay()*/
}

/***************************************************************************//**
 * @brief Delays number of msTick Systicks (typically 1 ms)
 * @param dlyTicks Number of ticks to delay
 ******************************************************************************/
void Delay(uint32_t dlyTicks)
{
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks) ;
}

/***************************************************************************//**
 * @brief  Main function
 ******************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();
CMU_ClockEnable(cmuClock_GPIO,true);
  /* If first word of user data page is non-zero, enable Energy Profiler trace */
  BSP_TraceProfilerSetup();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
    while (1) ;
  }

  /* Initialize LED driver */

  BSP_LedsInit();
  BSP_LedSet(0);
  GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0);
  Delay(1000);
  GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0);

  while (1) {
      GPIO_PinOutClear(LED_PORT_E,15);

      GPIO_PinOutSet(LED_PORT_E,15);
  }
}

Solution

  • Give delay in while loop .

     while (1) {
              GPIO_PinOutClear(LED_PORT_E,15);
              Delay(1000);
              GPIO_PinOutSet(LED_PORT_E,15);
              Delay(1000);
              }
    

    If configuration of pins is ok then LEDS start blinking.