Hi guys,
I've been trying for several days to use different slaves on the same SPI bus.
I'm using ESP32 devKit V2 (wrover kit) with 16MB memory.
If I use slaves one by one, they work very well,
but when I try to integrate them to work in the same sketch, they no longer work correctly.
I assumed it was necessary to reconfigure the SPI at each slave change, but unfortunately this was not enough.
At the bus I have:
- SD card
- MAX3421
- w5500
What I observe is that I can get MAX3421 and SD to work, but as soon as I introduce Ethernet module (w5500), the other two peripherals stop working.
Could you please advise me the best way to deal with this problem?
Examples or advice on the correct way to handle this situation?
Detail:
I'm using freertos and I have a mutex, named: mutex_SPI
which allows me to avoid simultaneous access of the peripherals to the bus.
At the moment I don't have particular efficiency and speed constraints,
I'm interested in starting by finding a way to make everything work.
SPI used: VSPI: SCK=18, MISO=19, MOSI=23
CS_SD=5
CS_MAX3421=27
CS_ETH=25
SD:
I'm using "SPClass" (SPI.h): SPIClass SPI_SD
and class SDFS: SDFS SD = SDFS(FSImplPtr(new VFSImpl()))
This is the initialization:
SPI_SD.begin(SPI_SCK, SPI_MISO, SPI_MOSI, CS_SD);
if(!SD.begin(CS_SD, SPI_SD, 4000000, "", 5, false))
{
ESP_LOGE(TAG, "ERROR SD NOT INIT");
}
MAX3421:
I'm using "SPClass" (SPI.h): SPIClass SPI_USB
This is the initialization:
SPI_USB.begin(SPI_SCK, SPI_MISO, SPI_MOSI, CS_MAX3421);
if (Usb.Init() == -1)
{
ESP_LOGE(TAG, "USB HOST OSC did not start");
}
Ethernet (w5500):
This is the initialization:
simplifyed code:
Ethernet.init(CS_ETH);
Ethernet.begin(mac);
if (Ethernet.hardwareStatus() != EthernetNoHardware)
{
vTaskDelay(100 / portTICK_PERIOD_MS );
if(Ethernet.linkStatus() != LinkOFF)
{
ESP_LOGD(TAG, "CABLE CONNECTED");
}
else
{
ESP_LOGE(TAG, "CABLE NOT CONNECTED");
}
}
After the three initializations, each of which takes place in its own specific dedicated task,
after ethernet initialization, I can no longer communicate with either the SD or the MAX3421 module, although they worked before.
And it's not enough for me to re-initialize again.
I really don't know what to do
How do we behave in these cases?
Thank you very much for your attention