-->
Page 1 of 2

GPIO read speed

PostPosted: Sun Nov 20, 2016 6:36 am
by worbo
I have a clock signal of 12kHz and on every rising edge I need to read the state of at least 4 of the GPIO pins. Unfortunately, it's a continous operation, so buffering the signal for slower read-out is not an option.
My first tests with a Wemos board (D1 mini) seem to indicate that the ESP8266 is not fast enough for this.

Is it possible to sample this quickly with an ESP8266 assuming further optimizations or should I be looking into other, faster chips?

Re: GPIO read speed

PostPosted: Mon Nov 21, 2016 10:18 am
by martinayotte
You should be able to read GPIO at proper speed by reading ESP GPIO INPUT register directly, its address is 0x60000318.

Re: GPIO read speed

PostPosted: Mon Nov 28, 2016 11:18 am
by worbo
Very simplified code
Code: Select all#define GPIO_IN ((volatile uint32_t*) 0x60000318)

void loop() {
  uint32_t data;
  while(!digitalRead(CLOCK)) { }
     
  // rising edge
  data = *GPIO_IN;

  // wait for falling edge
  while(digitalRead(CLOCK)) {}
}

I tried it with interrupts as well as in the main loop() function, both weren't fast enough at 12kHz.

Any more ideas? Maybe replace digitalRead() with a GPIO_IN read and some bit-banging?

Re: GPIO read speed

PostPosted: Mon Nov 28, 2016 12:07 pm
by martinayotte
I doubt your code doesn't work at 12KHz. But just in case that digitalRead() is not fast enough, try it that way :

Code: Select all#define CLOCK 0x0010 // GPIO4 bit mask
#define DATA 0x0020 // GPIO5 bit mask
#define GPIO_IN ((volatile uint32_t*) 0x60000318)

void loop() {
  uint32_t data;
  while((*GPIO_IN & CLOCK) == 0) { }     
  // rising edge
  data = (*GPIO_IN & DATA);
  // wait for falling edge
  while((*GPIO_IN & CLOCK) == 1) {}
}