On webpage http://abyz.me.uk/rpi/pigpio/examples.html you can find Tiny GPIO Access that defines minimal set of C functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).

I am using this code for bitbanging on I2C dedicated channels (GPIO2 and GPIO3). However, after bitbanging, I2C kernel communication (linux/i2c-dev.h) is no longer working. Is there a way to de-initialize GPIO access and let kernel do its work as previously?

The initialization part of the code is

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>

int gpioInitialise(void)
   int fd;

   piRev = gpioHardwareRevision(); /* sets piModel and piRev */

   fd = open("/dev/gpiomem", O_RDWR | O_SYNC) ;

   if (fd < 0)
      fprintf(stderr, "failed to open /dev/gpiomem\n");
      return -1;

   gpioReg = (uint32_t *)mmap(NULL, 0xB4, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);


   if (gpioReg == MAP_FAILED)
      fprintf(stderr, "Bad, mmap failed\n");
      return -1;
   return 0;

Yes, set the GPIO back into mode ALT0 (needed by GPIO 2/3 to be in I2C mode).

Tiny GPIO has the following define to use to set that mode.

#define PI_ALT0 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.