Unexpected behavior using SW vs. HW SPI on ESP32 with the SX127x LoRa module #7423
Replies: 1 comment
-
Posted at 2020-11-28 by @MaBecker hi, the hardware SPI’s are only avaiable on specific pins: SPI1: SCLK D14, MISO D12, MOSI D13 SPI2: SCLK D18, MISO D19, MOSI D23 Posted at 2020-11-28 by rj Great, I'll try that out 🙂! I did think about that many, many, many, times, but I just could not track down the information, where did you find it? Posted at 2020-11-28 by @MaBecker I just know it and it should be added to the docs as mentioned in this issue. More details about the ESP32 SPI can be found here. Posted at 2020-11-28 by @MaBecker
to be honest, it took me several hours to figure this out, when I tried to use it the first time Posted at 2020-11-28 by @MaBecker Which hardware are you using to captured the radio outputs? Posted at 2020-11-28 by rj
Glad to know I'm not alone 😁
I'm using the HackRF One I bought a few years back, it's been priceless! When a signal is not received, it's invaluable to know that the transmitter at least tries to do something--that's a good half of the setup I don't have to debug right there ⭐⭐⭐. Posted at 2020-11-28 by rj OK, so I've replaced the pins with the ones you mention--but still struggle a little 🙂! Setup now looks like this (only the pins has changed):
And the code like this:
I've attached two screenshots of the SCK, MOSI and MISO, and it looks like nothing is happening on the MOSI line when using HW SPI with this example--I'm sure I just missed something obvious, I hope someone can spot it 😬🙌? (are there restrictions to the CS/RESET pins as well perhaps? Do I need to set the I/O "mode" for some of the pins manually? Do I need to specify more parameters when using HW- as opposed to SW SPI?) Attachments: Posted at 2020-11-28 by @MaBecker Do you what use soft or hard SPI (SPI1 and SPI2 is hardware)? What about the baud rate, don't you need a specific one? Posted at 2020-11-28 by rj Sorry, the example was not clear enough 🙂. I just made an example where I could easily switch between using SW spi (the stuff with ".. new SPI ()... "), and HW SPI (the one with "SPI2 ... ") for this demonstration. The problem occurs when I try to use the HW spi (the block I commented out in the example of #8). Yes, setting the baud rate was what started this endeavour in the very first rate--but first I need HW SPI to work though 🙂. Posted at 2020-11-28 by rj So to be completely clear, this is what's not working for me 🙂:
(Edit: Perhaps I should try to remove the SX127x stuff, and boil it down to only using the SPI, I'll be back.) Posted at 2020-11-28 by rj OK, perhaps I'm on to something (my own mistake 😬). I'm using a chip called AI Thinker-A1S, which I'm sure I've read somewhere should be compatible with the Espressif ESP32-WROVER (which uses the IOs MaBe mentioned), but I can't find that information now. Reading the datasheet of the AI Thinker-A1S, it looks like the IOs used for SPI is a little different though; MISO is IO21 and not IO19 (although they use a terminology like Is there anything I can do to make HW SPI work on this device? Posted at 2020-11-28 by rj In any case this is what I see on the SPI lines for HW and SW SPI of this example code (nothing on MOSI):
Attachments: Posted at 2020-11-28 by rj OK, I think I got to the heart of the problem, SPI1 is working beautifully (I haven't tested with the SX library and all that, but I get data through MOSI now). Apparantly capacitors on the AI Thinker ESP32-A1S prevents us from using GPIOs 5, 18, 19 and 23 for SPI (according to this comment (Edit: may be incorrect, the comment is referring to a dev. kit using the same chip)). Thank you MaBe for your help! Edit: still having issues, posting a new question 🙂 Posted at 2020-12-06 by @MaBecker Which SX127x devices are you using for send and receive? Posted at 2020-12-06 by rj AI Thinker Ra-02 Posted at 2020-12-06 by @MaBecker This kind? Posted at 2020-12-06 by rj Yes. If you tell me what you're up to, I might be able to provide you with better answers. Posted at 2020-12-06 by @MaBecker mainly I like to build up some LoRa knowledge. Some sender and a gateway Edit: Using Espruino as firmware. Posted at 2020-12-06 by rj Ah ok, I wasn't sure if you were still in debugging mode. Great to have more Espruino guys using this 👍. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-27 by rj
Hey 👋,
I'm playing around with the SX127x library in a large project, and have some problems using the HW SPI with the SX127x module.
I've boiled an example down based on the example code.
This works (soft SPI):
But this doesn't (HW SPI, same
txConfig
, same pins):My LoRa module is the AI Thinker RA-02.
Anyone have an idea as to why 🙂?
I've attached examples of the captured radio outputs, but I think I've boiled it down to the HW SPI being off in some way, and not setting the radio up properly to begin with.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions