This problem is SOLVED in post:
Post
For the folks running MicroPython. This problem is very easily solved. The trick is getting the SPI host numbers aligned properly. and MicroPython didn’t make it easy to see that is what the issue is.
I am going to use the ESP32 as an example with this.
The SPI host numbers for the ESP32 series of chips is 0, 1 and 2. Those are the numbers that you would use when creating the display. 0 is usually reserved for SPIRAM and SPIFLASH so stick with using 1 and 2. If you create an SPI bus using the built in SPI class in MicroPython the host numbers are shifted by 1 digit. so if you want to create a touch driver and that touch driver uses SPI and is attached to the same pins for SPI (except for the CS) you need to add 1 to the number you passed to the display. so if you passed in a 1 to the display then you would pass a 2 when creating the SPI bus.
Now the SD Card which also uses SPI. There is a parameter called “slot” that you need to specify. It is a keyword only parameter so when constructing the SDCard object you need to use slot=num
in order to set it. slot number 0 and 1 are native SD/MMC slots and slots 2, 3 and 4 are… you guessed it, they are SPI host numbers Those numbers do not align with the ones passed to the display or to the SPI Bus. It’s as easy as this. add 2 to the number you passed to the display. If the display is on it’s own bus and the touch and SD are shared then you will add a 1 to the host number you passed to the touch driver.
real SPI host numbers are
0, 1 and 2
MicroPython SPI host numbers are
1, 2 and 3
and the SD card SPI Host numbers are
2, 3 and 4
so
real SPI SD
0 == 1 == 2
1 == 2 == 3
2 == 3 == 4.
just remember that each device on a bus MUST have it’s own CS pin when sharing the bus. If there is only a single device on the bus you can save connecting the CS and attach it to ground instead.
That is what has been causing all the grief with getting the SD card reader working properly. The card reader a lot of time is on the same bus as the touch panel. so they MUST have the same host when being used. just have to get the numbers right is all.