-
• #2
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
-
• #3
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?
-
• #5
I just know it
to be honest, it took me several hours to figure this out, when I tried to use it the first time
;-)
-
• #6
Which hardware are you using to captured the radio outputs?
-
• #7
to be honest, it took me several hours to figure this out, when I tried to use it the first time ;-)
Glad to know I'm not alone 😁
Which hardware are you using to captured the radio outputs?
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 ⭐⭐⭐.
-
• #8
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):
const PIN_SCK = D18; const PIN_MISO = D19; const PIN_MOSI = D23; const PIN_CS = D5; // NSS const PIN_RESET = D21; // Configuration const txConfig = { bandwidth: 0, freq: 434330000, power: 17, forcePaBoost: true, };
And the code like this:
// Setup const spi = new SPI(); spi.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI }); const sx = require("SX127x").connect({ spi: spi, cs: PIN_CS, rst: PIN_RESET }); // HW SPI (replace the three lines above) // SPI2.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI }); // const sx = require("SX127x").connect({ spi: SPI2, cs: PIN_CS, rst: PIN_RESET }); // Poll DIO0 for interrupts setInterval(function () { sx.onIRQ(); }, 100); sx.setTxConfig(txConfig); // Transmit sx.send("Hello", function () { console.log("TX done"); });
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?)
2 Attachments
-
• #9
Do you what use soft or hard SPI (SPI1 and SPI2 is hardware)?
In the sample of post #8 is using software.What about the baud rate, don't you need a specific one?
-
• #10
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 🙂.
-
• #11
So to be completely clear, this is what's not working for me 🙂:
const PIN_SCK = D18; const PIN_MISO = D19; const PIN_MOSI = D23; const PIN_CS = D5; // NSS const PIN_RESET = D21; // Configuration const txConfig = { bandwidth: 0, freq: 434330000, power: 17, forcePaBoost: true, }; // HW SPI (replace the three lines above) SPI2.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI }); const sx = require("SX127x").connect({ spi: SPI2, cs: PIN_CS, rst: PIN_RESET }); // Poll DIO0 for interrupts setInterval(function () { sx.onIRQ(); }, 100); sx.setTxConfig(txConfig); // Transmit sx.send("Hello", function () { console.log("TX done"); });
(Edit: Perhaps I should try to remove the SX127x stuff, and boil it down to only using the SPI, I'll be back.)
-
• #12
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
VSPIIDHS1STROBE
instead ofVSPID
as the WROVER does).Is there anything I can do to make HW SPI work on this device?
-
• #13
In any case this is what I see on the SPI lines for HW and SW SPI of this example code (nothing on MOSI):
const PIN_SCK = D18; const PIN_MISO = D19; const PIN_MOSI = D23; // HW SPI SPI2.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI}); SPI2.write([1,2,3]); // SW SPI // const spi = new SPI(); // spi.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI}); // spi.write([1,2,3]);
2 Attachments
-
• #14
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 🙂
-
• #15
Which SX127x devices are you using for send and receive?
-
• #16
AI Thinker Ra-02
-
• #18
Yes. If you tell me what you're up to, I might be able to provide you with better answers.
-
• #19
mainly I like to build up some LoRa knowledge.
Some sender and a gateway
Edit: Using Espruino as firmware.
-
• #20
Ah ok, I wasn't sure if you were still in debugging mode. Great to have more Espruino guys using this 👍.
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.
2 Attachments