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

Issue with buttons_led_init when trying to program with HX711

Hello,

I am using a nRF52840-DK with an HX711 in SES. I have been utilizing the code provided by Vidar Berg that can be seen here

I downloaded the zip file, unzipped it, and then copied it into the ble_app_uart example folder, running the pca10056_s140 SES project file with the main.c, hx711.c, and hx711.h files from Vidar's code above. Everything complies correctly but I noticed the device wasn't advertising. Whenever I upload the code, LED5 begins flickering/flashing rapidly, and no other LEDs turn on. After some debugging I realized the program is prompting an error in buttons_led_init. The error is highlighted below in the main.c file.

Other people have gotten this code to work quite easily, and I trust that is correct considering Vidar wrote it. However after hours of debugging, changing memory, using DK boards, modifying files, and searching the devzone, I have found nothing that has worked. I am new to the nRF community so I feel like I may be making an obvious mistake. If anyone has any suggestions or tips, it would be much appreciated! Thanks in advance.

Parents Reply Children
  • Hi,

    I see you sent me the older project where you used overlapping pins for buttons and HX711. Since my memory is like a goldfish I forgot about it, and found it again, writing down the procedure to show you how you can debug similar problems in the future:

    Stepping in bsp_init() -> app_button_init() you can see that the second iteration in the while loop tries to configure a button on GPIO pin 24. This fails on line 174 in app_button.c, which is caught by the error check on line 175. The error code is 8, which is NRF_ERROR_INVALID_STATE. This error is likely caused by the pin already being configured for GPIOTE, and you can confirm this by stepping into nrfx_gpiote_in_init(), where you will see this clearly on line 523-525 in nrfx_gpiote.c. So you need to specify different pins on line 30-32 in hx711.c (I selected 2, 3 and 4, but it does not matter as long as they are available).

    Once fixed, we get the second problem you described, where NRF_ERROR_NO_MEM is returned from the call to bsp_init(). We will apply the same debugging technique here, stepping down in the code to see what is going on. Stepping down the hiararcy you can find that NRF_ERROR_NO_MEM is returned from the call to nrf_drv_gpiote_in_init() on line 174 in app_button.c (which is in the implementation of app_button_init()), when this is called with pin 11. The pin number is not directly relevant here, though, but we take not of it.

    Then, step into nrfx_gpiote_in_init() when pin 11 is configured, and step through it. You will see that the error code is set on line 557 in nrfx_gpiote.c, and this is because the internal channel_port_alloc() on line 529 returned NO_CHANNELS. It is not very easy to see, but this happens because loop in channel_port_alloc ends without finding an available low-power "channel". This is because NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS is too low, which in turn is because GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS in your sdk_config.h is too low. So the fix is to set GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS to 5 in your sdk_config.h.

  • Perfect, thank you so much for your very clear and thorough answer. I appreciate you taking the time to help me in figuring this out!

Related