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

User avatar
By michaeltandy
#53818 Just to clarify, there is a single 32-bit clock configuration word, and the references above to "SPI_CLKCNT_N", "SPI_CLKCNT_L_S" and so on describe how the different bits of the word work.

The constants that start SPI_CLKDIV/SPI_CLKCNT but don't end in _S indicate the maximum value for that part of the configuration word, while those ending in _S indicate the shift, in bits, of that part of the configuration word.

So for example you can do this in the Arduino IDE:
Code: Select all  SPI0CLK = 0xC7C7004;

which would be interpreted like so:
Code: Select all0xC7C7004 = 0000 1100 0111 1100 0111 0000 0000 0100
            EPPP PPPP PPPP PPNN NNNN HHHH HHLL LLLL

P = Predivider = 80MHz / (0b0001100011111 + 1) = 80MHz/800 = 100kHz
N = Divided clocks per SPI clock = (0b000111 + 1) = 8 = 25kHz SPI clock rate
H = 0b000000 = 0
L = 0b000100 = 4


H < L so difference (4) is number of clock periods clock is low. So the clock will be low 4 cycles, high 4 cycles (i.e. 50% duty cycle)

And looking at the output on an oscilloscope, that's exactly what I see! Thanks, metalphreak!