Here is the Arduino code toggling an IO pin. It takes 400ns.
PORTD |= 0x04;
PORTD &= 0xFB;
Here is the mbed code toggling an IO pin. It takes 645ns. (longer than Arduino)
pin5 = 1;
pin5 = 0;
It's not completely fair. Because it would certainly take longer if one uses DigitalWrite(2,1) and DigitalWrite(2,0) (the encapsulated Arduino function calls) to toggle IO pin, which is equivalent to the instance method in mbed code.
Then it leads to my question: is there a direct register accessing method to make mbed toggle IO pin faster?
Here is the Arduino code toggling an IO pin. It takes 400ns.
Here is the mbed code toggling an IO pin. It takes 645ns. (longer than Arduino)
It's not completely fair. Because it would certainly take longer if one uses DigitalWrite(2,1) and DigitalWrite(2,0) (the encapsulated Arduino function calls) to toggle IO pin, which is equivalent to the instance method in mbed code.
Then it leads to my question: is there a direct register accessing method to make mbed toggle IO pin faster?