How to use nrf_delay_us on Arduino boards with the nrf52840

I tried to include the "nrf.h" but I am still not able to use it.

Here is my simple code which I am trying to upload to the Nano 33 BLE Sense:

#include "mbed.h"
#include "pinDefinitions.h"
#include "nrf.h"

#ifndef D_OUT_PIN
  #define D_OUT_PIN          P1_11

mbed::DigitalInOut dOutPin( D_OUT_PIN );

void setup() {

void loop() {
  dOutPin = 1;
  dOutPin = 0;

Any help is appreciated :slight_smile:

I figured it out!

I needed to #include "nrf_delay.h" instead of #include "nrf.h".

I measured 1.25 us high time and 1.75 us low time with my scope. Not great given the clock rate should be 64 MHz with a clock cycle period of 15.625 ns... but also not absolutely terrible for my needs.

Given the terrible inaccuracies of Arduino's micros and delayMicroseconds methods on the nrf52 boards, hopefully others find this much better delay method helpful!


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.