Page 1 of 1

Questions regarding SPI hardware

Posted: Tue May 22, 2018 9:00 pm
by Danie.
Hello Guys,

i am about to design a little project and need to communicate with multiple SPI devices.
I am not sure, which pins i should use.
Due to the fact that I need much GPIO pins within the project, the SPI interface should use the minimum possible IO count.

I want to implement:
- JTAG (these pins are fixed, i know)
- SD Card
- SPI Display (additional with Touchcontroller)
- 433 Mhz Tranceiver Module
- NFC Reader / Writer

Could JTAG and SD Card can share pins? Of course i know that i cannot use SD card and JTAG at the same time.
Can I use a single SPI driver (native, because of speed) and control additional CS lines over software (I think the original SPI driver only supports 3 devices?)

CS lines should also be controllable over I2C portexpander, because otherwise i will run out of GPIO´s. :roll:

What would be a good practice here?

Kind Regards
Danie

Re: Questions regarding SPI hardware

Posted: Wed May 23, 2018 9:15 pm
by kolban
Howdy Danie, welcome to the forum.

As you realize, SPI is commonly four lines ... CLK, MOSI, MISO and CS. All the devices on your SPI bus all connect to CLK, MOSI and MISO at the same time but only the single device which has its CS line driven should respond/honor the SPI traffic. Assuming you can dedicate pins for CLK, MOSI and MISO then, ideally you would use other lines ... 1 for each SPI slave ... for CS. However if you are running low on GPIO pins, as you say, using a port expander through I2C to map out additional signals for CS would work. For example, using I2C you would use 2 lines ... CLK and SDA and would be rewarded with 8 or 16 (or more) lines attachable to your CS for SPI slaves. The down side is that you would have to drive I2C to correctly set CS for the desired device prior to making other SPI communications calls.

Re: Questions regarding SPI hardware

Posted: Thu May 24, 2018 12:26 am
by Danie.
Thank you for your reply!

Do you think its a good idea to use only one SPI-Bus for all devices? I know this is the reason why this is called bus :lol:
But especially for the display its necessary to transfer a high amount of data.
If i update the display quite often i do not have much time to perform other spi read or write operations.

In the datasheet of the esp32 i see, that there are 3 different kind of SPI interfaces available:
VSPI, HSPI and SPI. Because of the display, i want to use the fastest SPI interface.
I do not clearly understand the datasheet - but i think the VSPI is the fastest - and this would be pins:
GPIO23 = MOSI, GPIO18 = SCK, GPIO19 = MISO :?:


Software related question:
The other SPI devices output an interrupt signal, when "something happend".
What happens, if I write data to the display and while writing an interrupt from an SPI device occurs and i immediately try to access another SPI device?
Is the data automatically transferred, after the display data is completely transmitted or how does the driver handle this?

Would it be a better practice, to use the VSPI for display + touchcontroller only and use an additional SPI-bus for the other spi devices? (for easier software development reasons?)

Kind Regards
Danie

Re: Questions regarding SPI hardware

Posted: Fri May 25, 2018 11:28 am
by Deouss
I also had similar questions what are differences between those SPI buses on esp32.
And why you think VSPI would be the fastest one?
As far as I know SPI standard can go 100MHz or even more. I have no clue what is max speed on ESP32 and really would love to know that. This is very very important question.
I looked into I2C and with its limitations it is probably better to go with technology called 1-wire that allows practically unlimited slaves on one wire bus line :o (plus ground).
It also should be more clarified in the Espressif docs how the bits and byte layout is controlled during spi data transfers.
The best functionality I think is remote control - it is amazing and should be called pwm control.