-->
Page 1 of 1

How to increase clk frequency on an output pin in ESP 12e?

PostPosted: Wed Oct 02, 2019 8:19 pm
by javadhabibi
Hi, I'm Using a ESP 12-e module in arduino IDE. I want to generate a clock and a data on my pins to communicate with a custom device. Something like this:
Image
This is my related piece of code:
Code: Select allpinMode(CLK , OUTPUT);
  pinMode(DOUT , OUTPUT);
//
void Write_Bit_0(void){
    digitalWrite( DOUT , LOW );
    digitalWrite( CLK , HIGH );
    digitalWrite( CLK , LOW );
  }
void Write_Bit_1(void){
    digitalWrite( DOUT , HIGH);
    digitalWrite( CLK , HIGH );
    digitalWrite( CLK , LOW );
  }
//
....


My problem is to increase CLK frequency. it seems that digitalWrite command take about 800 ESP clock to run!(I measured it with ESP.getCycleCount()).
Can anyone suggest a solution to increase CLK frequency up to 8 Mhz?
Thanks

Re: How to increase clk frequency on an output pin in ESP 1

PostPosted: Thu Oct 03, 2019 11:42 pm
by Pablo2048
You probably don't get 8MHz, but you have to direct access GPIO registers - for example see this https://forum.arduino.cc/index.php?topic=423340.0

Re: How to increase clk frequency on an output pin in ESP 1

PostPosted: Fri Oct 04, 2019 2:39 am
by btidey
That looks like SPI with the right clock phase and polarity set up and data length set to 8.

By using the hardware SPI you can get very high clock frequencies; 8MHz no problem. Plus much lower software overhead as you are writing bytes rather than bit banging.

Re: How to increase clk frequency on an output pin in ESP 1

PostPosted: Sun Oct 13, 2019 3:08 am
by eriksl
Also if your timing such tight, it may not be possible to use arduino.

I suggest you move your question to the arduino section. This has nothing to do with hardware.