GPIO speed for bit banging

22 May 2018


Using Mbed OS (v5.8.4), GPIOs can only toggle about every 5 µs max. Why? They can toggle on the order of tens of ns using the bare metal LPCOpen platform.

How can I reliably create one-shot pulses measured in single digit microseconds on Mbed OS?


I'm trying to interface a DS18B20 1-wire temperature sensor to my Embedded Artists LPC4088QSB board. I see that there are several drivers out there, but they're not working in my scenario.

I have my board underclocked - down from the max 120 MHz core / 60 MHz peripheral clocks to 24 MHz for both. The fastest I can toggle a GPIO output pin gives me about a 20 µs pulse or more, but I need to be able to do < 15 µs reliably. (Running the board at full speed lets me get down in the 5 µs range. I was able to read the temperature from the device a couple times, but the pulsewidths aren't uniform, which makes me unsure if it's possible to do reliably this way, even at the max clock speed.)

int main()
   DigitalOut testPin(P0_26);

      CriticalSectionLock lock;

      for (int i = 0; i < 10; i++)
         LPC_GPIO0->SET = (1 << 26);
         LPC_GPIO0->CLR = (1 << 26);

   // ...

Probing the output pin with an oscilloscope shows the same pulsewidths regardless of whether I use the DigitalOut interface, or if I access the registers directly.

EDIT: Update

I got it toggling quickly by modifying mbed-os-example-blinky, so I guess I'm doing something else in my program to cause it. Investigation continues...

29 May 2018