problem in GPIO reading

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

problem in GPIO reading

1,211 Views
aravindpb5009
Contributor III

   I try to read a gipo pin status either 0 or 1 in digital form but when i try to read my assigned pin was not getting o/p 

please let me know the solution . in below i provided the code 

/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/* Standard C Included Files */
#include <stdio.h>
#include <string.h>
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_i2c.h"
#include "fsl_i2c.h"
#include <stdlib.h>
#include <string.h>
#include "pin_mux.h"
#include "fsl_device_registers.h"
#include "fsl_common.h"
#include"lpc8xx_i2c.h"
#include"fsl_usart.h"
/*******************************************************************************
* Definitions
******************************************************************************/

#define BOARD_LED_PIN 23U
#define SWITCH_PORT 0U
#define SWITCH_PIN 28U


static void EXAMPLE_USARTInit(void);
void delay_ms(int a);

int main(void)
{

gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0,};
gpio_pin_config_t SWITCH_config = { kGPIO_DigitalInput, 0,};


GPIO_PortInit(GPIO, BOARD_LED_PORT);
GPIO_PinInit(GPIO, BOARD_LED_PORT, BOARD_LED_PIN, &led_config);

GPIO_PortInit(GPIO, SWITCH_PORT);
GPIO_PinInit(GPIO, SWITCH_PORT, SWITCH_PIN, & SWITCH_config);

while(1)
{
while(GPIO_PinRead(GPIO,SWITCH_PORT, 1u << SWITCH_PIN)==1);

GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u << BOARD_LED_PIN);

} // end of while 1

} // end of main

static inline uint32_t GPIO_PinRead(GPIO_Type *base, uint32_t port, uint32_t pin)
{
return (uint32_t)base->B[port][pin];
}

Labels (5)
0 Kudos
3 Replies

1,026 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Aranvind,

In order for me to better assist you, can you please confirm the microcontroller that you are using.

Thank you,

Sabina

0 Kudos

1,026 Views
aravindpb5009
Contributor III

LPC824, Mcuxpresso IDE 

Thanks& Regards 

Aravind P

0 Kudos

1,026 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Aravind,

After checking your code, I dont see where the clock for the port is being initialized. Please try to enable to correct clock for the led and switch you are using. 

If you would like to see an example, you can use the LPCXpresso824max_gpio_led_ouput example which is available in the SDK.

This example uses a switch to toggle a led just as you are doing. 

You can download the sdk here.

Best Regards,

Sabina