Skip to content

Instantly share code, notes, and snippets.

@nophead
Last active March 31, 2019 06:55
Show Gist options
  • Save nophead/f78bca73d730285ad16300087c58a783 to your computer and use it in GitHub Desktop.
Save nophead/f78bca73d730285ad16300087c58a783 to your computer and use it in GitHub Desktop.
How to set up ESP8266 HSPI to spy on a SPI bus
void hspi_slave_begin() {
pinMode(SCK, SPECIAL); // Both inputs in slave mode
pinMode(MOSI, SPECIAL);
SPI1C = 0; // SPI_CTRL_REG MSB first, single bit data mode.
SPI1S = SPISE | SPISBE | SPISCD | 0x3E0;// SPI_SLAVE_REG, set slave mode, WR/RD BUF enable, CMD define, enable interrupts
SPI1U = SPIUSSE; // SPI_USER_REG. SPI_CK_I_EDGE
SPI1CLK = 0; // SPI_CLOCK_REG
SPI1U1 = 7 << SPILADDR; // SPI_USER1_REG, set address length to 8 bits
SPI1U2 = 7 << SPILCOMMAND; // SPI_USER2_REG, set command length to 8 bits
SPI1S1 = (length * 8 - 1) << SPIS1LBUF; // SPI_SLAVE1_REG, SPI_SLV_BUF_BITLEN = 12 bytes
SPI1S3 = 0xF1F200F3; // SPI_SLAVE3_REG,, Define command 0 to be write buffer, others something doesn't match
SPI1P = 1 << 19; // SPI_PIN_REG, Clock idle high, seems to cause contension on the clock pin if set to idle low.
ETS_SPI_INTR_ATTACH(_hspi_slave_isr_handler, 0);
ETS_SPI_INTR_ENABLE();
}
@gavofih
Copy link

gavofih commented Mar 31, 2019

Is it possible to set SPI_SLV_BUF_BITLEN more than 64 bytes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment