I can't control by pin number.

Thank you for your help.
We are currently developing hardware using nrf52840. I would like to use pin numbers to control LED lighting, but when the port number is 0, I can use "NRF_GPIO_PIN_MAP(0, xx)" to control the LEDs, but when the port number is 1, I can't control the LEDs. NRF_GPIO_PIN_MAP (1. xx)" will not work. I am new to development, so it could be due to some rudimentary part. Thank you in advance for your help.

  • Hello,

    Based on the NRF_GPIO_PIN_MAP() API, I assume you are using nRF5 SDK. Please correct me if I am wrong, and also, please specify what SDK release version you are using.

    I am not quite sure what you are trying to do, but perhaps you can test this main.c file with the SDK_17.1.0\examples\peripheral\pin_change_int example:

    /**
     * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup pin_change_int_example_main main.c
     * @{
     * @ingroup pin_change_int_example
     * @brief Pin Change Interrupt Example Application main file.
     *
     * This file contains the source code for a sample application using interrupts triggered by GPIO pins.
     *
     */
    
    #include <stdbool.h>
    #include "nrf.h"
    #include "nrf_drv_gpiote.h"
    #include "app_error.h"
    #include "boards.h"
    
    #define MY_GPIO NRF_GPIO_PIN_MAP(1,9)
    
    #ifdef BSP_BUTTON_0
        #define PIN_IN BSP_BUTTON_0
    #endif
    #ifndef PIN_IN
        #error "Please indicate input pin"
    #endif
    
    #ifdef BSP_LED_0
        #define PIN_OUT BSP_LED_0
    #endif
    
    /*#ifdef MY_GPIO BSP_LED_0
        #define PIN_OUT MY_GPIO
    #endif*/
    
    #ifndef PIN_OUT
        #error "Please indicate output pin"
    #endif
    
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        nrf_drv_gpiote_out_toggle(MY_GPIO);
    }
    /**
     * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
     * and configures GPIOTE to give an interrupt on pin change.
     */
    static void gpio_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
    
        err_code = nrf_drv_gpiote_out_init(MY_GPIO, &out_config);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
        in_config.pull = NRF_GPIO_PIN_PULLUP;
    
        err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(PIN_IN, true);
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        gpio_init();
    
        while (true)
        {
            // Do nothing.
        }
    }
    
    
    /** @} */
    

    At least, it allows me to control P1.09 as an output pin, which will toggle whenever I am pressing button1 on the DK. 

    If you are using some other library that doesn't work with port 1 (NRF_GPIO_PIN_MAP(1,xx), please let me know what you are trying to use. If possible, please upload the project (you can zip the project folder and upload it here). Perhaps there is some bug or setting that doesn't work in your current setup.

    Best regards,

    Edvin

Related