Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By worbo
#58415 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?
User avatar
By worbo
#58794 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?
User avatar
By martinayotte
#58800 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) {}
}