Ble nano v2:: Arduino IDE :: OneWire Ds18B20


#1

Hi,

I know that there are some few Topic that are some similar but no one of they works (maybe layer 8 problem), then the way I prefer to present my problem will be explaining what I tried with no results.

The exact problem is use ds18B20 with ble nano V2.

Searching in google I found (OneWire DS18B20 (solved)), that at first look seems to be the solution that I needed, I noticed that some contributor of library OneWire had solved the problem originated in before thread with the following commits in git (https://github.com/PaulStoffregen/OneWire/pull/33), therefore I installed the OneWire library just by using the packages manager inside Aruino IDE (OneWire version 2.3.3).

The problem is that at including OneWire.h (#include <OneWire.h>) this throw errors that I will put at the end.

My suspisious is that the commits that solve the problem for the nano ble v1 are specifically for nano ble v1 and not work with nano ble v2, I think that because reading the commits I saw that the macros used to solve the problem are defined for RBL_NRF51822 (and ble nano v2 is RBL_NRF51832 that is obvously different) (see line 155 in https://github.com/PaulStoffregen/OneWire/pull/33/commits/a1e66d5beef7d4a686042680d8abbe66bb9ef55e).

so, any help will be great!.

The errors of the compiler are:

In file included from /tmp/arduino_modified_sketch_717179/BLE_beacon.ino:16:0:
/root/Arduino/libraries/OneWire/OneWire.h:254:2: warning: #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture." [-Wcpp]
 #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture."
  ^
In file included from /root/Arduino/libraries/OneWire/OneWire.cpp:142:0:
/root/Arduino/libraries/OneWire/OneWire.h:254:2: warning: #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture." [-Wcpp]
 #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture."
  ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::reset()':
/root/Arduino/libraries/OneWire/OneWire.cpp:169:15: error: 'noInterrupts' was not declared in this scope
  noInterrupts();
               ^
/root/Arduino/libraries/OneWire/OneWire.cpp:171:13: error: 'interrupts' was not declared in this scope
  interrupts();
             ^
/root/Arduino/libraries/OneWire/OneWire.cpp:165:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
                        ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::write_bit(uint8_t)':
/root/Arduino/libraries/OneWire/OneWire.cpp:202:16: error: 'noInterrupts' was not declared in this scope
   noInterrupts();
                ^
/root/Arduino/libraries/OneWire/OneWire.cpp:207:14: error: 'interrupts' was not declared in this scope
   interrupts();
              ^
/root/Arduino/libraries/OneWire/OneWire.cpp:210:16: error: 'noInterrupts' was not declared in this scope
   noInterrupts();
                ^
/root/Arduino/libraries/OneWire/OneWire.cpp:215:14: error: 'interrupts' was not declared in this scope
   interrupts();
              ^
/root/Arduino/libraries/OneWire/OneWire.cpp:199:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
                        ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::read_bit()':
/root/Arduino/libraries/OneWire/OneWire.cpp:230:15: error: 'noInterrupts' was not declared in this scope
  noInterrupts();
               ^
/root/Arduino/libraries/OneWire/OneWire.cpp:237:13: error: 'interrupts' was not declared in this scope
  interrupts();
             ^
/root/Arduino/libraries/OneWire/OneWire.cpp:227:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
                        ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::write(uint8_t, uint8_t)':
/root/Arduino/libraries/OneWire/OneWire.cpp:256:15: error: 'noInterrupts' was not declared in this scope
  noInterrupts();
               ^
/root/Arduino/libraries/OneWire/OneWire.cpp:259:13: error: 'interrupts' was not declared in this scope
  interrupts();
             ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::write_bytes(const uint8_t*, uint16_t, bool)':
/root/Arduino/libraries/OneWire/OneWire.cpp:267:18: error: 'noInterrupts' was not declared in this scope
     noInterrupts();
                  ^
/root/Arduino/libraries/OneWire/OneWire.cpp:270:16: error: 'interrupts' was not declared in this scope
     interrupts();
                ^
/root/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::depower()':
/root/Arduino/libraries/OneWire/OneWire.cpp:314:15: error: 'noInterrupts' was not declared in this scope
  noInterrupts();
               ^
/root/Arduino/libraries/OneWire/OneWire.cpp:316:13: error: 'interrupts' was not declared in this scope
  interrupts();
             ^
exit status 1
Error compilando para la tarjeta RBL_Blend2.

#2

Hi @psigelo,

To fix the errors, try:

  1. Navigate to the board package installation folder. Find and edit wiring_constants.h by adding:
#define interrupts() __enable_irq()
#define noInterrupts() __disable_irq()
  1. Edit OneWire.h by adding:
#elif defined(BLE_NANO2)
#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->IN >> (Pin_Arduino_to_nRF52(pin))) & 1ul}
#define DIRECT_WRITE_LOW(base, pin)    {NRF_GPIO->OUTCLR = (1ul << (Pin_Arduino_to_nRF52(pin)))}
#define DIRECT_WRITE_HIGH(base, pin)    {NRF_GPIO->OUTSET = (1ul << (Pin_Arduino_to_nRF52(pin)))}
#define DIRECT_MODE_INPUT(base, pin)    nrf_gpio_cfg_input(Pin_Arduino_to_nRF52(pin), NRF_GPIO_PIN_NOPULL)
#define DIRECT_MODE_OUTPUT(base, pin)   nrf_gpio_cfg_output(Pin_Arduino_to_nRF52(pin))
#define DELAY_MICROSECONDS(us)		nrf_delay_us(us)

Hope it works for you!

Guohui


#3

First at all: Thanks and Sorry for the late response, I really need help with this beacause it seems hard to understand the problem, actually your answer is not the thing I need to do the system works, but I think that you probably could help me step by step if I present the problems like they arrise to me.

My current problem is that the constructor of OneWire is shutting down the ble nano v2, I will put an example that not show anything in the Serial Monitor

#include <nRF5x_BLE_API.h>
#include <OneWire.h>

OneWire  ds(D2);  // on pin 10 (a 4.7K resistor is necessary)

void setup(void) {
  Serial.begin(9600);
  Serial.println("starting");
}

void loop(void) {
  delay(100);
}

This example compile but not seems to work correct (I expect “starting” in the Serial Monitor).


#4

It was my error, using the correct library I can run the example that I presented before, but the OneWire is not working.

Trying to solve my problem in the correct library I put your code and some problems arises, the first was easy to solve adding the following lines:

  #define IO_REG_MASK_ATTR
  #define IO_REG_BASE_ATTR

in the #elif defined (BLE_NANO2) scope, but the second problem is not so easy: in OneWire.cpp I changed all the delayMicroseconds to DELAY_MICROSECONDS in order to actually use the correct function but the compiler started to throw error:

 OneWire_direct_gpio.h: 234: 56: error: 'nrf_delay_us' was not declared in this scope
 #define DELAY_MICROSECONDS (us) nrf_delay_us (us)

Looking in the other solutions that I found before they add #include <nRF51822_API.h> inside the #elif defined (BLE_NANO2) scope, like you can see in https://github.com/PaulStoffregen/OneWire/pull/33/files

Then I try including #include <nRF5x_BLE_API.h> in the same way, but the error continues.

some idea to solve this?

thanks


#5

Hi @psigelo,

You can try removing the included <nRF5x_BLE_API.h> and define the DELAY_MICROSECONDS(us) to be delayMicroseconds(us).