Skip to content
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

Library not working with latest ESP32 framework (fix inside) #3

Open
Xanderr opened this issue Jan 14, 2023 · 3 comments
Open

Library not working with latest ESP32 framework (fix inside) #3

Xanderr opened this issue Jan 14, 2023 · 3 comments

Comments

@Xanderr
Copy link

Xanderr commented Jan 14, 2023

Hi,

I wanted to use this library for a project of mine, but encountered some problems. On my laptop the library didn't work at all and on my PC it was fine (testing with the debug sketch, via platform.io). Turns out, the ESP framework had an update recently and my laptop was using this one while my PC used a very old one. I tried a few versions, and everything above version 5.0.0 causes the library to stop working.

After some research, I found the following issue: espressif/arduino-esp32#7556. Here a commit was references adding some functionality regarding thread safety for SPI on the ESP32: espressif/arduino-esp32@bdeef89

This commit adds a destructor for the SPI class, which is the root of the problem. This destructor is called instantly after running the library's begin() function, causing the SPI interface to stop working (took a bit of time to figure this one out).

Inspecting the code of this library, I noticed that the SPIClass object passed in the begin() function was not passed as reference, causing the object to be copied instead. This caused the copy to be destroyed after the begin functions ends (since it no longer has references), which in turn calls the new destructor. At this point, the library doesn't work anymore. If you run the debug sketch, it will say "All registers read as 0xFF or 0x00! Is the nRF905 connected correctly?".

The fix was pretty simple though. I modified this library slightly to pass the SPI instance via the constructor as reference, and now it works again as the destructor is no longer called :) I also added that the library starts the SPI class automatically when calling begin().

You can look at it here: https://github.com/Xanderr/nRF905-arduino. If you want, I can make a PR for this?

@ZakKemble
Copy link
Owner

Hi Xanderr, thanks for looking into this! Yes, please make a PR :D

@Xanderr
Copy link
Author

Xanderr commented Jan 22, 2023

@ZakKemble Alright :) I'll do it somewhere next week. I'll also update the examples to reflect the change.

As a sidenote, I pretty much finished the nRF905 implementation in my side project and it has been working flawlessly. So the change didn't have any weird side effects or anything :p

@Xanderr
Copy link
Author

Xanderr commented Apr 17, 2023

@ZakKemble Sorry it took so long, I just didn't get around to do some finishing touches (like updating & testing the examples). But I just made the PR, let me know if there's anything else I can do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants