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

User avatar
By javadhabibi
#84011 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
User avatar
By btidey
#84028 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.