- My goal is: [Use IO5 as gpio for spi-cs pin ]
- My actions are: [Enable SPI with
spi.mosi_gpio=23
,spi.sclk_gpio=18
,spi.miso_gpio=spi.cs0_gpio=-1
to write data/command with ESP32’s VSPI module] - The result I see is: [Tried using IO4 as gpio for spi-cs that is working. But not sure why the same code with IO5 as gpio for spi-cs does not work]
- My expectation & question is:
My config_schema as below:
- ["spi.enable", true]
- ["spi.mosi_gpio", 23]
- ["spi.miso_gpio", -1]
- ["spi.sclk_gpio", 18]
- ["spi.cs0_gpio", -1] #why IO5 not working???
- ["myDev", "o", {title: "My Device"}]
- ["myDev.cs_index", "i", 0, {title: "spi.cs*_gpio index, 0, 1 or 2"}]
- ["myDev.spi_freq", "i", 80000000, {title: "SPI frequency"}]
- ["myDev.cs_pin", "i", 4, {title: "CS pin gpio"}]
Code to test is :
static void myDev_spi_write(const uint8_t *data, uint32_t size){
struct mgos_spi *spi = mgos_spi_get_global();
if (!spi) {
LOG(LL_ERROR, ("SPI is disabled, set spi.enable=true"));
return;
}
struct mgos_spi_txn txn = {
.cs = -1,
.mode = SPI_MODE,
.freq = mgos_sys_config_get_myDev_spi_freq(),
};
txn.hd.tx_data = data;
txn.hd.tx_len = size;
txn.hd.dummy_len = 0;
txn.hd.rx_len = 0;
txn.hd.rx_data = NULL;
mgos_spi_run_txn(spi, false, &txn);
}
Code to write with CS pin toggle by GPIO:
uint8_t cmd=0xFE;
mgos_gpio_write(mgos_sys_config_get_myDev_cs_pin(), 0); //CS 0
myDev_spi_write(&cmd, 1);
mgos_gpio_write(mgos_sys_config_get_myDev_cs_pin(), 1); //CS 1
The question is :
ESP32’s SPI seems very picky. CS= IO4 works but CS=IO5 doesn’t work. Also tried CS=IO10 but it didn’t work either. Other pins like CS=IO25 also working.
Why?