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

User avatar
By picstart
#12202
Code: Select allPIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);//GPIO12 - HSPIQ MISO, not using it for MISO but as LCD reset
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode GPIO13 - HSPID MOSI
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode GPIO14 - CLK
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode GPIO15 - CS


Are you sure this is correct Ex PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode GPIO13 - HSPID MOSI could this be the CLK pin and not the MOSI pin?
User avatar
By picstart
#12206
Code: Select all//// code to write 1 and 2 bytes

    void spiwrite(uint8_t c) {
       while (READ_PERI_REG(SPI_CMD(HSPI))&SPI_USR); //waiting for spi module available
       WRITE_PERI_REG(SPI_USER1(HSPI), (7 & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S);   // 8 bits
       WRITE_PERI_REG(SPI_W0(HSPI), (uint32)data); // the data to be sent
       SET_PERI_REG_MASK(SPI_CMD(HSPI), SPI_USR);   // send
    }

    #define lowByte(w) ((uint8_t) ((w) & 0xff))
    #define highByte(w) ((uint8_t) ((w) >> 8))

    void spiwrite16(uint16_t w) {
       while (READ_PERI_REG(SPI_CMD(HSPI))&SPI_USR); //waiting for spi module available
       WRITE_PERI_REG(SPI_USER1(HSPI), (15 & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S); // 16 bits
       WRITE_PERI_REG(SPI_W0(HSPI), lowByte(w) << 8 | highByte(w));
       SET_PERI_REG_MASK(SPI_CMD(HSPI), SPI_USR);   // send
    }

I'm not getting this code
A) void spiwrite(uint8_t c) would pass c but it sends data in WRITE_PERI_REG(SPI_W0(HSPI), (uint32)data); // the data to be sent
B) I'm unsure of the register sizes would appear to load 40 bits into the registers 8 plus 32
C) void spiwrite16(uint16_t w) appears to load 32 bits 16 plus 16
D) I get the peripheral select but hoe do you know the GPIO pins will be CLK GPIO13 and GPIO14
Anyway I for the first time saw an inclination that there might be documentation at least in Chinese of the SPI interface when looking at the expressif bbs.
User avatar
By picstart
#12604 Ok,
I have the hardware HSPI working and as expected it is a speed improvement over a bit banged SPI interface.
There are interface engines embedded in the esp8266 (UART SPI I2C) silicon. They are exposed by setting certain registers.
Not all IO pins are capable of being selected for these engines. The engines can only be assigned ( muxed) to a fixed set of pins. The names of I/O pins for SPI CLK MISO MOSI CS are obvious in external devices but
obtuse in the esp8266 world of register notation.
The code below initializes HSPI on the esp8266. The esp8266 is a master to an external slave device
Code: Select all   /////// init the remap to HSPI
   WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); //clear bit9
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);//GPIO12 - HSPIQ MISO, not using it for MISO but as LCD A0
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode GPIO13 - HSPID MOSI
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode GPIO14 - CLK
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode GPIO15 - CS

Notice that obtusely MTCK is MOSI, MTMS is CLK, MTDO is CS ( chip select) .
The good news is that this code works and that it can be wrapped in an init spi call.
Thanks to all that helped
User avatar
By draco
#12608
picstart wrote:I have the hardware HSPI working and as expected it is a speed improvement over a bit banged SPI interface.

Nice work!

I hope these improvements will go into the next firmware update :)

When you say that
picstart wrote:The code below initializes HSPI on the esp8266. The esp8266 is a master to an external slave device
do you mean that this particular code initializes the esp8266 as a master, or that it is only capable of acting as the master?