mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-11 04:57:38 +00:00
spi_example: fix the example to pass in esp32s2beta
This commit is contained in:
@@ -57,6 +57,17 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
||||
#define GPIO_SCLK 15
|
||||
#define GPIO_CS 14
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#define RCV_HOST HSPI_HOST
|
||||
#define DMA_CHAN 2
|
||||
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
#define RCV_HOST SPI2_HOST
|
||||
#define DMA_CHAN RCV_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) {
|
||||
@@ -78,7 +89,9 @@ void app_main()
|
||||
spi_bus_config_t buscfg={
|
||||
.mosi_io_num=GPIO_MOSI,
|
||||
.miso_io_num=GPIO_MISO,
|
||||
.sclk_io_num=GPIO_SCLK
|
||||
.sclk_io_num=GPIO_SCLK,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
};
|
||||
|
||||
//Configuration for the SPI slave interface
|
||||
@@ -106,7 +119,7 @@ void app_main()
|
||||
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);
|
||||
|
||||
//Initialize SPI slave interface
|
||||
ret=spi_slave_initialize(HSPI_HOST, &buscfg, &slvcfg, 1);
|
||||
ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, DMA_CHAN);
|
||||
assert(ret==ESP_OK);
|
||||
|
||||
WORD_ALIGNED_ATTR char sendbuf[129]="";
|
||||
@@ -130,7 +143,7 @@ void app_main()
|
||||
.post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
|
||||
data.
|
||||
*/
|
||||
ret=spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
|
||||
ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
|
||||
|
||||
//spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
|
||||
//received data from the master. Print it.
|
||||
|
Reference in New Issue
Block a user