GPIO — General purpose input/output
General Purpose Input/Output (GPIO) is organized as a port of up to 32 I/Os (package dependent), allowing up to 32 pins to be accessed and controlled through a single port. Each GPIO can be individually accessed
The GPIOs have the following user-configurable characteristics:
Supports up to 32 GPIOs
8 GPIO and analog channels for SAADC, COMP or LPCOMP input
Configurable output driver strength
Internal pull-up and pull-down resistors
Wake-up from high or low trigger on all pins
Interrupt triggered by a change of state on any pin
All pins can be used by the PPI task/event system
One or more GPIO outputs can be controlled via PPI and GPIOTE channels
All pins can be individually mapped to interface blocks for layout flexibility
GPIO state changes captured on the SENSE signal can be stored in the LATCH register
The GPIO port peripheral implements up to 32 pins, PIN0 to PIN 31. Each of these pins can be individually configured in the PIN_CNF[n] register (n=0…31).
**The following parameters can be configured through these registers: **
Direction (input/output)
Driver Strength
Enable pull-up and pull-down resistors
Pin detection
Input buffer disconnected
Analog Input (for selected pins)
The PIN_CNF register is a reserved register. For more information on the reserved registers, refer to the POWER - POWER supply chapter on page 78.
Pin Configuration
Pins can be individually configured to detect high or low levels on their input levels through the SENSE field of the PIN_CNF[n] register.
When the correct level is detected on any such configured pin, the sensing mechanism will set the high detection signal.
Each pin has a separate detect signal. The default behavior, as defined in the DETECTMODE register, is that the detect signals from all pins on the GPIO port are combined into a common detect signal that is routed throughout the system and can then be utilized by other peripherals.
See Figure 21: GPIO Port and GPIO Pin Details on page 112. This mechanism works in both ON and OFF modes.
Download the official manual:
https://infocenter.nordicsemi.com/pdf/nRF52810_PS_v1.3.pdf
https://infocenter.nordicsemi.com/pdf/nRF52820_PS_v1.2.pdf
https://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.7.pdf
https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.5.pdf
/********************************************************************************
* @file bsp_gpio.c
* @author jianqiang.xue
* @version V1.0.0
* @date 2021-04-09
* @brief gpio initialization
********************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include #include "RTE_Components.h" #include CMSIS_device_header #include "nrf_gpio.h" #include "nrf_drv_gpiote.h" #include "sdk_common.h" #include "bsp_exti.h" #include "bsp_gpio.h" /* Private Includes ----------------------------------------------------------*/ #include "business_gpio.h" #include "business_function.h" /* Private Variables ---------------------------------------------------------*/ /* Private Function Prototypes -----------------------------------------------*/ static nrf_gpiote_polarity_t get_exti_event(bsp_gpio_exti_int_event_t exti_type) { if (BSP_GPIO_EXTI_INT_LOWFALL == exti_type) { return NRF_GPIOTE_POLARITY_HITOLO; } else if (BSP_GPIO_EXTI_INT_HIGHRISE == exti_type) { return NRF_GPIOTE_POLARITY_LOTOHI; } else if (BSP_GPIO_EXTI_INT_FALLRISE == exti_type) { return NRF_GPIOTE_POLARITY_TOGGLE; } else { return NRF_GPIOTE_POLARITY_TOGGLE; } } static nrf_gpio_pin_pull_t get_nrf_pull(bsp_gpio_pin_pull_t pull) { if (pull == BSP_GPIO_PIN_PULLUP) { return NRF_GPIO_PIN_PULLUP; } else if(pull == BSP_GPIO_PIN_PULLDOWN) { return NRF_GPIO_PIN_PULLDOWN; } else { return NRF_GPIO_PIN_NOPULL; } } /* Public Function Prototypes ------------------------------------------------*/ /** * @brief [Deinitialization] Disable the specified pin function (restore to floating input) * @note NULL * @param *gpiox: NULL * @param pin: pin number * @retval None */ void bsp_gpio_deinit(void *gpiox, uint8_t pin) { nrf_gpio_cfg_default(pin); } /** * @brief [Initialization] Set the pin to output mode * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param out_mode: BSP_GPIO_PIN_OUT_OD open-drain output, BSP_GPIO_PIN_OUT_PP push-to-disable output, BSP_GPIO_PIN_AF_OD multiplexed open-drain, BSP_GPIO_PIN_AF_PP multiplexed push-to-disable * @retval None */ void bsp_gpio_init_output(void *gpiox, uint8_t pin, bsp_gpio_pin_out_t out_mode) { nrf_gpio_cfg_output(pin); } /** * @brief [Initialization] Set the pin to input mode * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param pull: BSP_GPIO_PIN_NOPULL no pull-up or pull-down, BSP_GPIO_PIN_PULLUP pull-up input, BSP_GPIO_PIN_PULLDOWN pull-down input * @retval None */ void bsp_gpio_init_input(void *gpiox, uint8_t pin, bsp_gpio_pin_pull_t pull) { nrf_gpio_cfg_input(pin, get_nrf_pull(pull)); } extern void gpiote_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action); /** * @brief [Initialization] Set the pin to [input + interrupt] mode * @param gpiox -- NULL * @param pin -- pin number * @param irqn -- NULL * @param exti_type -- BSP_GPIO_EXTI_INT_LEVEL level trigger, BSP_GPIO_EXTI_INT_EDGE edge trigger * @param exti_event -- BSP_GPIO_EXTI_INT_LOWFALL low level trigger (falling edge), BSP_GPIO_EXTI_INT_HIGHRISE high level trigger (rising edge), BSP_GPIO_EXTI_INT_FALLRISE high or low level trigger or any level change * @param pull -- BSP_GPIO_PIN_NOPULL no pull-up or pull-down, BSP_GPIO_PIN_PULLUP pull-up input, BSP_GPIO_PIN_PULLDOWN pull-down input */ void bsp_gpio_init_input_exit(void *gpiox, uint8_t pin, uint8_t irqn, bsp_gpio_exti_int_type_t exti_type, bsp_gpio_exti_int_event_t exti_event, bsp_gpio_pin_pull_t pull) { static bool flag = 0; ret_code_t err_code; if (flag == 0) { err_code = nrf_drv_gpiote_init(); APP_ERROR_CHECK(err_code); flag = 1; } nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(exti_type); config.pull = get_nrf_pull(pull); config.sense = get_exit_event(exit_event); err_code = nrf_drv_gpiote_in_init(pin, &config, gpiote_event_handler); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(pin, true); } /** * @brief Set the pin level status * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param state: BSP_GPIO_PIN_RESET low level, BSP_GPIO_PIN_SET high level * @retval None */ void bsp_gpio_set_pin(void *gpiox, uint8_t pin, bsp_gpio_pin_state_t state) { if (state) { nrf_gpio_pin_set(pin); } else { nrf_gpio_pin_clear(pin); } } /** * @brief Flip pin level state * @note NULL * @param *gpiox: NULL * @param pin: pin number * @retval None */ void bsp_gpio_set_toggle(void *gpiox, uint8_t pin) { nrf_gpio_pin_toggle(pin); } /** * @brief Get the specified gpio status * @note NULL * @param *gpiox: NULL * @param pin: pin number * @retval 0 -- low level, 1 -- high level */ bool bsp_gpio_get_state(void *gpiox, uint8_t pin) { return (bool)nrf_gpio_pin_read(pin); } /** * @brief Multiplex the specified pin as an ADC pin (multiplex analog input) * @note NULL * @param *gpiox: NULL * @param pin: pin number * @retval None */ void bsp_gpio_init_adc(void *gpiox, uint8_t pin) { } /** * @brief Initialize i2c pins * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param arf: reuse value * @retval None */ void bsp_gpio_init_i2c(void *gpiox, uint8_t pin, uint8_t arf) { } /** * @brief Initialize uart pin * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param arf: reuse value * @retval None */ void bsp_gpio_init_uart(void *gpiox, uint8_t pin, uint8_t arf) { } /** * @brief Initialize tim_ch pin * @note NULL * @param *gpiox: NULL * @param pin: pin number * @param arf: reuse value * @retval None */ void bsp_gpio_init_tim(void *gpiox, uint8_t pin, uint8_t arf) { } /******************************************************************************** * @file bsp_gpio.h * @author jianqiang.xue * @version V1.0.0 * @date 2021-04-09 * @brief GPIO control ********************************************************************************/ #ifndef __BSP_GPIO_H #define __BSP_GPIO_H /* Includes ------------------------------------------------------------------*/ #include #include /* Public enum ---------------------------------------------------------------*/ /** * @brief GPIO Bit SET and Bit RESET enumeration */ typedef enum { BSP_GPIO_PIN_RESET = 0U, BSP_GPIO_PIN_SET } bsp_gpio_pin_state_t; typedef enum { BSP_GPIO_PIN_NOPULL = 0U, BSP_GPIO_PIN_PULLUP, BSP_GPIO_PIN_PULLDOWN } bsp_gpio_pin_pull_t; typedef enum { BSP_GPIO_PIN_OUT_OD = 0U, BSP_GPIO_PIN_OUT_PP, BSP_GPIO_PIN_AF_OD, BSP_GPIO_PIN_AF_PP } bsp_gpio_pin_out_t; typedef enum { BSP_GPIO_EXTI_INT_LEVEL = 0U, // Level trigger BSP_GPIO_EXTI_INT_EDGE, // Edge triggered } bsp_gpio_exti_int_type_t; typedef enum { BSP_GPIO_EXTI_INT_LOWFALL = 0U, // Low level trigger (falling edge) BSP_GPIO_EXTI_INT_HIGHRISE, // High level trigger (rising and falling edge) BSP_GPIO_EXTI_INT_FALLRISE // High or low level trigger or any level change } bsp_gpio_exti_int_event_t; /* Public Function Prototypes ------------------------------------------------*/ // General pin initialization void bsp_gpio_deinit(void *gpiox, uint8_t pin); void bsp_gpio_init_output(void *gpiox, uint8_t pin, bsp_gpio_pin_out_t out_mode); void bsp_gpio_init_input(void *gpiox, uint8_t pin, bsp_gpio_pin_pull_t pull); void bsp_gpio_init_input_exit(void *gpiox, uint8_t pin, uint8_t irqn, bsp_gpio_exti_int_type_t exti_type, bsp_gpio_exti_int_event_t exti_event, bsp_gpio_pin_pull_t pull); // Initialize peripheral pins void bsp_gpio_init_adc(void *gpiox, uint8_t pin); void bsp_gpio_init_i2c(void *gpiox, uint8_t pin, uint8_t arf);
Previous article:[BSP layer] [nrf52832] [nrf52840] [nrf52810] [nrf52820] [bsp_exti] exti/gpioe configuration and use
Next article:[nrf51][nrf52] Developing ibeacon guide
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- I hope this book "PCB Design Secrets" will be passed on to you!
- [National Technology Low Power Series N32L43x Evaluation] 3. Key Driver + SPI_LCD Screen Driver
- A comic book about CircuitPython and Mu
- Is there any ADR3433 chip that can be replaced by PINTOPIN?
- 【Distributed temperature and humidity acquisition system】+temperature and humidity acquisition module
- MSP430 Remote Upgrade Solution
- Calculate the frequency of the sinusoidal signal collected by msp430
- I recently used a chip that is compatible with both RS232 and RS485, but I don't know which pins are A and B for RS485.
- [ATmega4809 Curiosity Nano Review] Configuring GPIO using MCC
- [Android Development Learning Road] 1-- Android Development Environment Construction