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

External input & output on nRF52840

Hello! I would like to use a predefined example from the nRF SDK and instead of the board's button, to use an external stimulus (let's say, an external button). Similarly, instead of turning on the board's LED, I want to set high a GPIO (let's say, external LED).

Now, I read a lot of questions on devzone about this and it's either very complicated or quite trivial. My idea is to just change in the file pca10056.h the line #define LED_1 NRF_GPIO_PIN_MAP (0,13) to #define LED_1 NRF_GPIO_PIN_MAP (0, xx). And similar for the BUTTON_1. My questions are:

1. Is this the only place where I need to do the modifications? It seems like only a mapping problem to me, but I think I might to re-write other files as well.

2. What do the (xx) need to be? (I read about this mapping in nRF52840's specs, @pag. 525, but I am not sure how to interpret that table into actual code). For instance, let's say that I'd like my A8 pin as a digital output (i.e. drive an external LED). Then, do I need to #define LED_1 NRF_GPIO_PIN_MAP (0, 32)? Or is A8 used already as AIN7, which is actually an analog input (see second line)? 

I am a bit confused after reading a lot about this; sorry for the basic question.

Parents
  • Hi, 

     

    1. Is this the only place where I need to do the modifications? It seems like only a mapping problem to me, but I think I might to re-write other files as well.

     Right. You need to modify the board header file (nRF5_SDK\components\boards\pca10056.h) to initialize the pin. It is related to how leds_buttons_init() in main.c initializes the buttons. Also, add to buttons_handler and leds_buttons_init() function in main.c:

     

    2. What do the (xx) need to be? (I read about this mapping in nRF52840's specs, @pag. 525, but I am not sure how to interpret that table into actual code). For instance, let's say that I'd like my A8 pin as a digital output (i.e. drive an external LED). Then, do I need to #define LED_1 NRF_GPIO_PIN_MAP (0, 32)? Or is A8 used already as AIN7, which is actually an analog input (see second line)? 

     A8 is P0.31 which means that it can either function as a normal GPIO or as an analog pin.

    -Amanda H.

  • Ok, Ms. , thank you for clarifying everything to me. Slight smile

    A8 is P0.31 which means that it can either function as a normal GPIO or as an analog pin.

    - regarding this I have two questions:

    (1) I did the modifications in the pca header and I noticed that the LEDs are active on low, therefore I changed LEDS_ACTIVE_STATE to 1, to make them turn on only on supply. But now, some LEDs remain turned on, some are off (even if I only set 1 LED on). I am not sure what their behaviour depends on. Do you have an idea where I should start to investigate and change the code accordingly? So that, only my desired GPIO or LED turns on at HIGH.

    (2) I will do a communication with another board using that GPIO, so I'd like to see what bits are changed and where. So, how could I know what registers get modified, when I set high the value of a specific digital output? (in order for me to actually use that bit change for my communication, further in my project).

    Thank you in advance & best regards!

  • Hi Alexa, 

    alexa said:
    Do you have an idea where I should start to investigate and change the code accordingly? So that, only my desired GPIO or LED turns on at HIGH.

    You could check the functions like buttons_handler and leds_buttons_init() if they are there.  You can test with the Blinky Example by commenting out Toggle LEDs while loop part. 

     

    alexa said:
    (2) I will do a communication with another board using that GPIO, so I'd like to see what bits are changed and where. So, how could I know what registers get modified, when I set high the value of a specific digital output? (in order for me to actually use that bit change for my communication, further in my project).

     Not sure I understand what you are trying to do. You can read the OUT register to check if the pin is high or low.

    -Amanda H.

  • Hi Amanda. Thanks for your reply, it's helping me.

    OUT register

    - how can I access this OUT register on the laptop, specifically? Is it related to the debugging option? Thank you!

Reply Children
  • Hi ! I am trying the idea which you suggested me the previous week, but I cannot achieve turning on one LED when supplying '1' (5V). When I change the LEDS_ACTIVE_STATE to 1, the other LEDs remain on for the whole time, without me specifying that. (i.e I don't modify the rest of the code)

    In order to debug this, I though of trying to understand these functions, like you suggested:

    functions like buttons_handler and leds_buttons_init()

    - but I cannot find them. Could you please tell me in which .c or .h file should I look for them? I also couldn't find this:

    commenting out Toggle LEDs while loop part

    - it should  probably be in main, but I only see one LED toggling, not more:

    #define LEDBUTTON_LED  BSP_BOARD_LED_2 /**< LED to be toggled with the help of the LED Button Service. */

    Could you plase tell me in which source files should I look for the mentioned functions? Thank you!

  • Hi Alexa,

    alexa said:
    When I change the LEDS_ACTIVE_STATE to 1, the other LEDs remain on for the whole time, without me specifying that. (i.e I don't modify the rest of the code)

    How did you add your external LED in the pca10056.h? Could you insert the related part in the pca10056.h?

     

    alexa said:
    but I cannot find them. Could you please tell me in which .c or .h file should I look for them?

     You can take a look at the BSP Example on how to control the LED. 

     

    alexa said:
    Could you plase tell me in which source files should I look for the mentioned functions?

    I think you are looking at the nRF5_SDK\examples\ble_peripheral\ble_app_blinky, but I mean nRF5_SDK\examples\peripheral\blinky.

    -Amanda H.

Related