SD card and nrf24 with ESP32

Hi,

In my project I need to have an SD card and nrf24(tmrh20 library). I am using the ESP32 30 pin (model not specified) as the mcu for the project. After doing some research I am now aware that there are two SPI busses that we can use on the ESP32 (VSPI and HSPI). I also came across how to use one or the other; but how would I use both; with each SPI bus hosting a peripheral device? (e.g. nrf24 on VSPI and SD on HSPI)

Thanks! :slight_smile:

Why not use one SPI bus for both?

3 devices are supported per ESP32 SPI buss

Create an instance of the SPI buss to be used, VSPI or HSPI. Pass to the object the SPI buss the object is to use.

SPIClass SPI0(HSPI);

MPU9250 IMU( SPI0, 15 );

I use the ESP32 SPI API, the SPI buss to use is assigned in the SPI Device Init.

int fInitializeSPI_Devices( spi_device_handle_t &h, int csPin)
{
  esp_err_t intError;
  spi_device_interface_config_t dev_config = { };  // initializes all field to 0
  dev_config.address_bits     = 0;
  dev_config.command_bits     = 0;
  dev_config.dummy_bits       = 0;
  dev_config.mode             = 3 ;
  dev_config.duty_cycle_pos   = 0;
  dev_config.cs_ena_posttrans = 0;
  dev_config.cs_ena_pretrans  = 0;
  dev_config.clock_speed_hz   = 5000000;
  dev_config.spics_io_num     = csPin;
  dev_config.flags            = 0;
  dev_config.queue_size       = 1;
  dev_config.pre_cb           = NULL;
  dev_config.post_cb          = NULL;
  spi_bus_add_device(HSPI_HOST, &dev_config, &h);
  // return intError;
  // return h;
} // void fInitializeSPI_Devices()

It is very important that any SPI devices on HSPI must be well behaved.

HSPI shares pins with the program loader. Pin TMS, GPIO_NUM_14, TDI, GPIO_NUM_12, and TCK, GPIO_NUM_13 during program load must not be made to change states during program upload. Example would be assigning one of those pins to a GPS module that starts sending data as soon as its done with the POST.

groundFungus:
Why not use one SPI bus for both?

I guess I could. Which esp32 pin should I use as the CS pin for the second device?(the first device would use the hardware CS pin)

GPIO_Num_15, 2, 4, 16, 17, 22, 13, 12, 27, 26, 25, are pins that can be used for CS other than GPIO_NUM_5; all of those pins are hardware pins. GPIO_NUM_15 is a good choice as its used for the HSPI SPI buss and if not using the other SPI buss why not use GPIO_NUM_15?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.