Manually controlling CS pins
When adding a SPI device, set its .spics_io_num to -1
//----- SETUP IO PINS -----
//Set CS high
gpio_set_level(EXAMPLE_SPI_PIN_CS, 1);
gpio_set_direction(EXAMPLE_SPI_PIN_CS, GPIO_MODE_OUTPUT);
//----- ADD A SPI DEVICE -----
spi_device_interface_config_t SpiDeviceInterfaceConfig1 = {
.clock_speed_hz = 10*1000*1000, //Clock out at 10 MHz
.mode = 0, //<<< SPI mode 0
.spics_io_num = -1, //<<< CS pin number (-1 = usunsed, you will control it yourself using GPIO)
.queue_size = 1, //<<< Number of transactions we want to be able to queue at a time using spi_device_queue_trans()
};
spi_bus_add_device(EXAMPLE_SPI_PORT_NAME, &SpiDeviceInterfaceConfig1, &OurSpiDeviceHandle1); //<<<You can use ESP_ERROR_CHECK() on this call if you are having issues
Now when you access other device, ensure you set CS low before you use it and high again afterwards
//CS Low
gpio_set_level(EXAMPLE_SPI_PIN_CS, 0);
//your SPI access code here...
//CS high
gpio_set_level(EXAMPLE_SPI_PIN_CS, 1);
