This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading Fast Changing Input from Input Pin

Hi, I am using nrf52832 dev-kit. I use P0.23 or P0.24 as an input pin. I am trying use this pin to read data from other device. When I use this pin like button, it can detect high or low states. But when I connect it to other device for communication it can not detect changes. I used stm32f4 board to check if other device is broken but stm could handle the data and it gave me correct data. My nrf52832 is always giving me 0. How can I fix that?

Parents
  • But when I connect it to other device for communication it can not detect changes.

     Do you mean that you connect it as a GPIO input, then as a SPI MOSI pin for instance (or UART or any other peripheral)? If that is the case, the peripheral will claim the selected GPIO. You cannot use a GPIO as input in addition to a UART TXD simultaneously.

    My nrf52832 is always giving me 0. How can I fix that?

     Regardless of which GPIO you're checking, you're always getting 0? Have you configured the respective gpio as input? You can do that by calling  nrf_gpio_cfg_input().

     

    Kind regards,

    Håkon

  • That device doesnt use SPI or UART, they have their own communication protocol, a pin as a clock and a pin as a data.

    I am checking P0.23 and configured it with this nrf_gpio_cfg_input(23,NRF_GPIO_PIN_PULLDOWN); . As I said before I use same pin with same configuration as a button it gives me one and zeros. But it cant detect ones that coming from other device. That device's period is 9 us for 1 bit.

Reply
  • That device doesnt use SPI or UART, they have their own communication protocol, a pin as a clock and a pin as a data.

    I am checking P0.23 and configured it with this nrf_gpio_cfg_input(23,NRF_GPIO_PIN_PULLDOWN); . As I said before I use same pin with same configuration as a button it gives me one and zeros. But it cant detect ones that coming from other device. That device's period is 9 us for 1 bit.

Children
  • If that pin is solely used as an input, there should be no restrictions, and it should work as a normal input pin. Have you scoped the signal to see if there's anything strange with the voltage or wave form going into the GPIO?

     

    Kind regards,

    Håkon

  • I dont have oscilloscope so I dont know how is signal. I listened other device with stm, and configure some of stm pins to copy those signals then I made connections between nrf and stm. When that device sends signal stm sends same signal to nrf, now I can read the data thanks to stm board. Whats the problem and how can I fix it?

  • Hi,

     

    Isolate the problem and test the specific pin.

    Start with a very small example, like blinky, and just read the input, and if it changes, increment a variable / toggle a LED or something (change to the GPIOs in question):

    /**
     * Copyright (c) 2014 - 2019, 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 blinky_example_main main.c
     * @{
     * @ingroup blinky_example
     * @brief Blinky Example Application main file.
     *
     * This file contains the source code for a sample application to blink LEDs.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "nrf_delay.h"
    #include "boards.h"
    #include "nrf_gpio.h"
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        /* Configure board. */
        bsp_board_init(BSP_INIT_LEDS);
        nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);
        /* Toggle LEDs. */
        while (true)
        {
            uint32_t pin_state = nrf_gpio_pin_read(BUTTON_1);
            /* Pin is active low */
            if (pin_state == 0) {
                static uint32_t active_count;
                active_count++;
                /* Visual aid */ 
                nrf_gpio_pin_toggle(LED_1);
            } else {
                /* Pin inactive - do nothing */
            }
        }
    }
    
    /**
     *@}
     **/
    

     

    Does this run? If yes, then there's no hardware problem (soldering or otherwise). It does not work? Then check your connections.

     

    Kind regards,

    Håkon

  • Sorry, it was my bad. Pin should be no pull up/down, I didnt know this. Before nrf I was working with stm32 it could handle the data when pin was pull down, so I thought it must be pull down. But I was wrong, thank you for answers.

  • Hi,

     

    No worries. Glad to hear that you found the root cause!

     

    Kind regards,

    Håkon

Related