New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SPIClass::setup
method for ESP32
#2360
Conversation
@mikee47 Can you check the CI errors ? /home/appveyor/projects/sming-sb483/Sming/Arch/Esp32/Core/SPI.cpp:251:8: error: 'class SPIClass' has no member named 'id'
this->id = busId;
^~
make[2]: *** [/home/appveyor/projects/sming-sb483/Sming/component-wrapper.mk:169: Arch/Esp32/Core/SPI.o] Error 1 |
2da8b39
to
be729b5
Compare
I might be doing something wrong, but creating an instance of SPIClass If I create it with The only change resulting in this behavior is the instance creation w/ VSPI or HSPI. in both cases I call the setup method. =========== Edit 1: Please wait to verify which SPI peripheral is in use. I changed HSPI to VSPI (in SPI.setup()) and now it works. =========== Edit 2: OK, I don't remember why I choose these pins, probably I was looking in the datasheet for HSPI pins, however there's no HSPI_MISO or HSPI_MOSI, so... Idk. But the use of the HSPI/VSPI perhipheral bugs me. Is it possible, that I used HSPI in my app's instance together with the VSPI in the global instance, therefore the app's SPI object really used HSPI (because VSPI should have been already taken by the global SPI instance)? Then if I leave the app only with the global SPI instance, it shouldn't be a problem to use HSPI or VSPI (and the specified pins). I don't get it. |
Bear in mind that SPI resources are not allocated until |
See also comments at top of #2130 regarding HSPI. |
Thanks, I'll prepare a sample tonight or tomorrow. Otherwise my current setup uses 3 chips, CS5460, MAX31865 and ADuM1401. They share the same bus and they do work fine now, with lower speeds though. (1M/4M). |
The sample below has 4 possible scenarios: Of all of them only the last one gives SPI communication. Here's the code:
Edit: the code above is wrong, here's the proper code with a pointer to the SPI obect:
And now with this code the only working condition is with the global SPI object and VSPI. ??? |
I've simplified your example and checked operation using loopback (connecting MISO to MOSI) and all configurations produce the same results. What device are you testing this with? There could be a more subtle issue at work here. Note: Tested using ESP-WROOM-32 module
|
@mikee47 I use ESP32-WROVER, but I guess it only has PSRAM and different pinout. Let me use your code and here I'll find one board for testing with MISO connected to MOSI. |
@mikee47 My tests confirm yours. Your example works with all combinations. I confirm that ESP32-WROVER SPI works flawlessly. I found two problems:
I hope my SPI will be robust now. Thanks for your time! :) |
Internal pullups are usually pretty weak, properly driven that should be easily overcome... Maybe there's a problem with the |
If I see unusual Btw may I ask you about the instance declaration? I want to use a reference to the SPI object I changed my classes to look like
Earlier I did something like
And finally I see you just declare it only with |
Yes, taking a copy of the object works and (sort of) takes a reference as the important member variable is |
@mikee47 you were right about the existence of some problem with the SPI, but it was my fault. I made a bug in one of my methods:
It is pretty interesting that I got a lot of time with both ICs working properly. I suspect that their call timing was reversed (like IC2, IC1 instead IC1, IC2). I just had another problem - there are two objects both working with the SPI peripheral. One of them does SPI transaction each second, and the other one each 500 ms. I found that once the first one is initialized and started its 1 second loop, breaks the initialization of the second IC. Therefore I first initialize the IC that doesn't have internal Timer started and later the one with the timer. How these two timers execute their tasks in relation to the SPI peripheral? |
Allows default bus/pin set to be changed for global
SPI
instance.