There is fastest way to set "1" or "0" to a GPIO in c++?
Now, we are using this function:
void gpioSet(int gpio, int value)
{
sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
fd = open(buf, O_WRONLY);
sprintf(buf, "%d", value);
write(fd, buf, 1);
close(fd);
}
Using this function, the CPU takes "time" to set it under C++.
The reason of this question, is that we are using an embedded linux board that have a bug in the SPI. I need to handle the CS (Chip Select) "manually" and this fuction takes time to set or reset the GPIO for the CS.
Thanks.
Instead of opening and closing the GPIO every time you need to write it, just open it once the first time you need to write it (or at boot time). Then you will skip the expensive operation. (Wrap this functionality in a class to make it clean.)
Also check that you aren't using a buffered write mode when you write to the GPIO.