/* SPI Slave example, receiver (uses SPI Slave driver to communicate with sender) This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/queue.h" #include "lwip/sockets.h" #include "lwip/dns.h" #include "lwip/netdb.h" #include "lwip/igmp.h" #include "esp_wifi.h" #include "esp_system.h" #include "esp_event.h" #include "nvs_flash.h" #include "soc/rtc_periph.h" #include "driver/spi_slave.h" #include "esp_log.h" #include "esp_spi_flash.h" #include "driver/gpio.h" /* SPI receiver (slave) example. This example is supposed to work together with the SPI sender. It uses the standard SPI pins (MISO, MOSI, SCLK, CS) to transmit data over in a full-duplex fashion, that is, while the master puts data on the MOSI pin, the slave puts its own data on the MISO pin. This example uses one extra pin: GPIO_HANDSHAKE is used as a handshake pin. After a transmission has been set up and we're ready to send/receive data, this code uses a callback to set the handshake pin high. The sender will detect this and start sending a transaction. As soon as the transaction is done, the line gets set low again. */ /* Pins in use. The SPI Master can use the GPIO mux, so feel free to change these if needed. */ #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 #define GPIO_HANDSHAKE 2 #define GPIO_MOSI 12 #define GPIO_MISO 13 #define GPIO_SCLK 15 #define GPIO_CS 14 #elif CONFIG_IDF_TARGET_ESP32C3 #define GPIO_HANDSHAKE 3 #define GPIO_MOSI 7 #define GPIO_MISO 2 #define GPIO_SCLK 6 #define GPIO_CS 10 #endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 #ifdef CONFIG_IDF_TARGET_ESP32 #define RCV_HOST HSPI_HOST #elif defined CONFIG_IDF_TARGET_ESP32S2 #define RCV_HOST SPI2_HOST #elif defined CONFIG_IDF_TARGET_ESP32C3 #define RCV_HOST SPI2_HOST #endif //Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high. void my_post_setup_cb(spi_slave_transaction_t *trans) { WRITE_PERI_REG(GPIO_OUT_W1TS_REG, (1<