Pin Muxing VSPI or HSPI
Posted: Wed Apr 14, 2021 12:31 pm
Hello,
I was able to use the SPI Slave API using the original pins and communicate with the master. I am now trying to switch the pins to the other side of the ESP32, however I'm not sure how to do so. If anyone could point me in the right direction or any links to an example of IO Muxing the ESP32 that would be great. I followed the documentation but I am not having any luck.
Edit After some testing, I was able to switch the CS pin while keeping everything else in the original pinout.
I was able to use the SPI Slave API using the original pins and communicate with the master. I am now trying to switch the pins to the other side of the ESP32, however I'm not sure how to do so. If anyone could point me in the right direction or any links to an example of IO Muxing the ESP32 that would be great. I followed the documentation but I am not having any luck.
Code: Select all
Original To Use
MISO 19 32
MOSI 23 33
SCLK 18 25
SS 05 26
- // SPI
- #include "driver/spi_slave.h"
- #define GPIO_CS 26 // I
- #define GPIO_SCLK 25 // I
- #define GPIO_MOSI 33 // I
- #define GPIO_MISO 32 // O
- #define RCV_HOST HSPI_HOST
- #define DMA_CHAN 2
- // SPI
- uint32_t sendbuf[1];
- uint32_t recvbuf[1];
- spi_slave_transaction_t t;
- esp_err_t ret;
- int n=0;
- void SetupSPI()
- {
- // Enable Pin Muxing to map the peripheral to their non-regular pins
- //
- gpio_iomux_in(GPIO_MOSI, VSPID_IN_IDX);
- gpio_iomux_out(GPIO_MISO, FUNC_GPIO19_VSPIQ, false);
- gpio_iomux_in(GPIO_SCLK, VSPICLK_IN_IDX);
- gpio_iomux_in(GPIO_CS, VSPICS0_IN_IDX);
- spi_bus_config_t buscfg={
- .mosi_io_num=GPIO_MOSI,
- .miso_io_num=GPIO_MISO,
- .sclk_io_num=GPIO_SCLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = 32,
- };
- spi_slave_interface_config_t slvcfg={
- .spics_io_num=GPIO_CS,
- .flags=0,
- .queue_size=3,
- .mode=1
- };
- //Initialize SPI slave interface
- ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, DMA_CHAN);
- printf("ret: %s\n", esp_err_to_name(ret));
- assert(ret==ESP_OK);
- //Set up a transaction of 128 bytes to send/receive
- t.length=32;
- t.trans_len=32;
- t.tx_buffer=sendbuf;
- t.rx_buffer=recvbuf;
- }
Code: Select all
MISO 19
MOSI 23
SCLK 18
SS 26