Digital input
응답
19. 2. 18 오후 10:14

 

Hello

I'm trying to turn on a relay if I keep pressing a push button but it does not work, I attach programming code and attached picture where the circuit is shown. I hope you can help me.

/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "XdkApplicationTemplate.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"

#include "BCDS_MCU_GPIO.h"
#include "BCDS_MCU_GPIO_Handle.h"

#include "em_gpio.h"

#include"BSP_BoardShared.h"

void extensionLedTask(void)
{

MCU_GPIO_Handle_T GPIOE;
/* initialize local variables */
int contador=0;
GPIOE.Port = gpioPortE;
GPIOE.Pin = 2;
GPIOE.Mode = gpioModePushPull;
GPIOE.InitialState = MCU_GPIO_PIN_STATE_HIGH;
/* Initialization activities for PTD driver */

GPIO_DriveModeSet (GPIOE.Port, gpioDriveModeHigh);
GPIO_PinModeSet (GPIOE.Port, GPIOE.Pin, GPIOE.Mode, GPIOE.InitialState);

uint8_t Gpio_Input = GPIO_PinInGet(gpioPortA,1);


while(contador<100){


if(Gpio_Input== 1)
{
/* Set data out register for the pin to 1 */
MCU_GPIO_WritePin(&GPIOE,MCU_GPIO_PIN_STATE_LOW);
printf("Enciende11 \n\r");
vTaskDelay(2000);
}
else{

MCU_GPIO_WritePin(&GPIOE,MCU_GPIO_PIN_STATE_HIGH);
printf("Apaga22 \n\r");
vTaskDelay(2000);
/* use suitable delay API. This delay API is for demo only. */
contador++;
}
}
}
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
	Board_EnablePowerSupply3V3(EXTENSION_BOARD);                                            
if (CmdProcessorHandle == NULL)
{
printf("Command processor handle is null \n\r");
assert(false);
}
BCDS_UNUSED(param2);
extensionLedTask();
}

 

0 (0 투표)
RE: Digital input
응답
19. 2. 19 오후 3:44 as a reply to Andres Rivera.

I already achieved what I wanted, in the part of the programming what I was missing was to configure the input pin, I added the following code:

GPIO_PinModeSet (gpioPortA, 1, gpioModeInputPull, 1);

GPIO_PinOutSet (gpioPortA, 1);

0 (0 투표)