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

OneWire on RedBearLab nRF51822

Hello!

I recently purchased a RedBearLab nRF51822 board where I want to use several DS1820 temperature sensors.

For dealing with the OneWire (1-wire) protocol I found this really promising and helpful library.

The problem is that the mentions library does not support the RedBearLab nRF51822 board. I contacted the creator of the library and he thinks its possible to support the board but where the official RedBearLab support advised my to ask here.

The library requires a special PIN setup depending on the used board and I don't know how to set this up correctly.

To avoid doubling the content I already asked for help in the Arduino forum: Need help porting OneWire to RedBearLab nRF51822 - this includes a more detailed explanation about my "problem".

Hopefully somebody can help me! Thank you very much in advance! :)

  • here is a starting point, just add a custom #elif with your board like this:

        #elif defined(BOARD_REDBEAR_XXX)
    
    
    #define DIRECT_READ(base, pin)          nrf_gpio_pin_read(pin)
    #define DIRECT_WRITE_LOW(base, pin)     nrf_gpio_pin_clear(pin)
    #define DIRECT_WRITE_HIGH(base, pin)    nrf_gpio_pin_set(pin)
    #define DIRECT_MODE_INPUT(base, pin)    nrf_gpio_cfg_input(pin)
    #define DIRECT_MODE_OUTPUT(base, pin)   nrf_gpio_cfg_output(pin)
    

    nrf_gpio_ functions are documented here: gpio abstraction or open "sdk/components/drivers_nrf/hal/nrf_gpio.h"

    cheers! OL

  • Thank you very much! Since I' using the nRF51 SDK for Arduino I came up with this version:

    #elif defined(RBL_NRF51822)
    
    #define PIN_TO_BASEREG(pin)             (0)
    #define PIN_TO_BITMASK(pin)             (pin)
    #define IO_REG_TYPE uint32_t
    #define IO_REG_ASM
    #define DIRECT_READ(base, pin)          nrf_gpio_pin_read(pin)
    #define DIRECT_WRITE_LOW(base, pin)     nrf_gpio_pin_clear(pin)
    #define DIRECT_WRITE_HIGH(base, pin)    nrf_gpio_pin_set(pin)
    #define DIRECT_MODE_INPUT(base, pin)    nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL)
    #define DIRECT_MODE_OUTPUT(base, pin)   nrf_gpio_cfg_output(pin)
    

    Is the NRF_GPIO_PIN_NOPULL for nrf_gpio_cfg_input correct? I'm able to compile everything and now the program does not hang at ds.search().

  • No I'm getting the error "No more addresses." Maybe one of the

    #define PIN_TO_BASEREG(pin)             (0)
    #define PIN_TO_BITMASK(pin)             (pin)
    #define IO_REG_TYPE uint32_t
    #define IO_REG_ASM
    

    is incorrect? I don't know what to configure there!? :(

Related