-
Notifications
You must be signed in to change notification settings - Fork 984
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
SPI object pointer inside library [SPI.setX (x = MISO, MOSI, SCLK, SSEL)] does not work. MCU hangs in _spi->begin() #2597
Comments
As a first guess :
If you set a SSEL to the SPI class then you want the CS pin managed by the hardware and not by the software (your application). Lines 335 to 345 in ffb23d6
So in your case:
So simply do not call this: Arduino_Core_STM32/libraries/SPI/src/utility/spi_com.c Lines 235 to 237 in ffb23d6
|
Dear @fpistm Aha! You got it. So, I commented the line: _mySPI-->setSSEL(_cs_Pin); then, I passed a simple SPI object (with no instance) // Create two instances of the ADS79xx ADCs
ADS79xx adcH(&SPI, MISO_PIN, MOSI_PIN, SCLK_PIN, CS_H_PIN);
ADS79xx adcL(&SPI, MISO_PIN, MOSI_PIN, SCLK_PIN, CS_L_PIN); and the code works as intended! I believe that my brain was trying to mirror the same implementation from ESP32 where you can pass the CS pin without any issues but your explanation makes a lot of sense. In my case, I want the library to take control over the CS pin since I am using two objects. Now, regarding the comments you made "not link to an SPI" did you mean that these are not Chip Select pins by default at the hardware level? Or do you simply mean "do not link them to an SPI object"? Finally, any comments regarding my last question on the preprocessor directives for compiling for STM2 or ESP32? Thanks for your prompt answer! 🍻 P.S. It would be awesome if you could have a look at the support request link I posted above in the |
No, just he pin you set as CS is not link to a SPI peripheral (SPIx) that's all.
Official one is
Unfortunately, I do not support/use PIO. PIO integrate this core but we support only the use in Arduino ecosystem (IDE, cli). |
Hi all
I will try to be as succinct as possible. Please bear with me.
In short. I am developing a custom library for the ADS79xx family of ADCs to use the library as a cross-platform one. So far, I have successfully tested it for ESP32, however, the implementation for STM32 fails when invoking the SPI set_Pin_ group:
but works when externally declaring the SPI object as:
SPIClass spi(MOSI_PIN, MISO_PIN, SCLK_PIN);
and passing it to the library.
EDIT: I forgot to mention that I am working on a custom board definition for the WeAct Mini Core STM32G474CEU which has no official support in
platformio
, however, I have started working on my own files. So far, they have worked fine (I2C works well, ADCs have some inaccuracies and it is still subject to thorough evaluation). I have started a support request here, however, I have not received any response yet.My library goes along the following lines:
ADS79xx.h
(skimmed version)and the corresponding
ADS79xx.cpp
file: (skimmed version too)my main code is the following:
main.cpp
(skimmed version)My code uses two ADCs to read 32 channels in total, however, the issues occur when setting up the SPI object pointer inside the library.
If I use the SPI object as follows:
and I delegate the initialization of the pins to the
ADS79xx::init()
method:inside
ADS79xx.cpp
init()
method:The MCU hangs
In contrast, if I pre-declare the pins from the SPI object by using this approach (based on info found here and in other Forums):
then pass by reference to the objects:
the MCU works normally. Here, I am feeding 1.21V and 5.00V to Channels 0 and 31, respectively:
Since I need to make this library work for other platforms, removing the option to pass the pins is far from ideal as the ESP32 implementation works fine (
_mySPI->begin({pins}
section) and thus I need to ask you for a solution to this.Why the pin setter methods are not working but when declaring the SPI object in advance works fine?
Finally, if you allow me to ask a slightly off-topic question. What are the "standard" preprocessor directives to compile for different boards? Say ESP32 and STM32
I have tried with
#if defined(STM32)
, however, that part of the code gets ignored.Please advise
Cheers
🍻
The text was updated successfully, but these errors were encountered: