Last active
March 31, 2019 06:55
-
-
Save nophead/f78bca73d730285ad16300087c58a783 to your computer and use it in GitHub Desktop.
How to set up ESP8266 HSPI to spy on a SPI bus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to set SPI_SLV_BUF_BITLEN more than 64 bytes?