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

User avatar
By Inq720
#84215 As the title implies, I want to connect two ESP8226 modules using Arduino IDE coding. In this case they happen to be Wemos boards. My main reference is the Espressif Technical Reference.

https://espressif.com/sites/default/files/documentation/esp8266-technical_reference_en.pdf

The technical document references a spi_test.c file that I found here:

https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/ESP8266_SDK/examples/peripheral_test/user/spi_test.c

The Master side is working fine and using a logic analyzer I can see that I am successfully sending...
* 2 byte command
* 4 byte address
* 13 byte data.
(see attached Capture.png)

Here is the output as expected on the Master side showing the register values that were sent to the slave.
Code: Select allMaster Send
SpiNum_HSPI(1610613056)
 SPI_CMD       [0x00000002]
 SPI_ADDR      [0xd3d4d5d6]
 SPI_CTRL      [0x0028a737]
 SPI_CTRL2     [0x00040011]
 SPI_CLOCK     [0x000e74e7]
 SPI_RD_STATUS [0x00000000]
 SPI_WR_STATUS [0x00000000]
 SPI_USER      [0xc8000070]
 SPI_USER1     [0x7cce0000]
 SPI_USER2     [0xf0000002]
 SPI_PIN       [0x0000001e]
 SPI_SLAVE     [0x00800200]
 SPI_SLAVE1    [0x02000000]
 SPI_SLAVE2    [0x00000000]
 ADDR[0x60000140],Value[0x03020100]
 ADDR[0x60000144],Value[0x07060504]
 ADDR[0x60000148],Value[0x0b0a0908]
 ADDR[0x6000014c],Value[0x0f0e0d0c]
 ADDR[0x60000150],Value[0x00000000]
 ADDR[0x60000154],Value[0x00000000]
 ADDR[0x60000158],Value[0x00000000]
 ADDR[0x6000015c],Value[0x00000000]
 ADDR[0x60000160],Value[0x00000000]
 ADDR[0x60000164],Value[0x00000000]
 ADDR[0x60000168],Value[0x00000000]
 ADDR[0x6000016c],Value[0x00000000]
 ADDR[0x60000170],Value[0x00000000]
 ADDR[0x60000174],Value[0x00000000]
 ADDR[0x60000178],Value[0x00000000]
 ADDR[0x6000017c],Value[0x00000000]


The problem is on the Slave side.
Although it is receiving and firing the interrupt based callback just fine, part of the incoming bytes are being misplaced. Here is the output for the same registers on the Slave device.

Code: Select allSlave Receiving
SpiNum_HSPI(1610613056)
 SPI_CMD       [0x00000002]
 SPI_ADDR      [0x00000000]
 SPI_CTRL      [0x0028a000]
 SPI_CTRL2     [0x00800011]
 SPI_CLOCK     [0x00000000]
 SPI_RD_STATUS [0x00000000]
 SPI_WR_STATUS [0x00000000]
 SPI_USER      [0xc9000040]
 SPI_USER1     [0x1dfeff00]
 SPI_USER2     [0x70000002]
 SPI_PIN       [0x0008001e]
 SPI_SLAVE     [0x405403e0]
 SPI_SLAVE1    [0x3aff1c70]
 SPI_SLAVE2    [0x00000000]
 ADDR[0x60000140],Value[0xd6d5d4d3]
 ADDR[0x60000144],Value[0x03020100]
 ADDR[0x60000148],Value[0x07060504]
 ADDR[0x6000014c],Value[0x0b0a0908]
 ADDR[0x60000150],Value[0x0000000c]
 ADDR[0x60000154],Value[0x00000000]
 ADDR[0x60000158],Value[0x00000000]
 ADDR[0x6000015c],Value[0x00000000]
 ADDR[0x60000160],Value[0x00000000]
 ADDR[0x60000164],Value[0x00000000]
 ADDR[0x60000168],Value[0x00000000]
 ADDR[0x6000016c],Value[0x00000000]
 ADDR[0x60000170],Value[0x00000000]
 ADDR[0x60000174],Value[0x00000000]
 ADDR[0x60000178],Value[0x00000000]
 ADDR[0x6000017c],Value[0x00000000]
Slave Received


Note the Command is correct (SPI_CMD) but the address (SPI_ADDR) = 0 and the addresses value is being populated in the first Data field. All the data is offset by this four bytes. Looking at the code for the slave side - there is no parameter or register #define for telling the lower level code what the address length is. Thus, it apparently defaults to zero and thus assumes the address is part of the data coming from the Master and places it into the Data registers.

Anyone know if there is some way of telling the slave side how to properly place the incoming Master bytes?

Thanks.
You do not have the required permissions to view the files attached to this post.
User avatar
By Inq720
#84270 On inspection of the Espressif API spi_interface.c, I found where the defaults are set for the Slave starting at line 132. The API does not support configuring the Slave side completely. It only allows setting bit order, mode and sub mode. Speed is set to 0 as the Master is in control of that setting for any slaves.

The default values for the Slave (line 132 spi_interface.c) are for a 1 byte Command and 1 byte Address.

Strangely enough... the Espressif demo spi_test.c has the Master configured to send an address of 4 bytes on line 151 of that file. This causes the errors described above. The defaults can easily be overridden in the spi_test.c starting at line 227 to look like:

Code: Select allos_printf("\r\n ============= spi init slave =============\r\n");
SPIInit(SpiNum_HSPI, &hSpiAttr);
SET_PERI_REG_BITS(SPI_SLAVE1(SpiNum_HSPI), SPI_SLV_WR_ADDR_BITLEN, 31, SPI_SLV_WR_ADDR_BITLEN_S);
SET_PERI_REG_BITS(SPI_SLAVE1(SpiNum_HSPI), SPI_SLV_RD_ADDR_BITLEN, 31, SPI_SLV_RD_ADDR_BITLEN_S);