Closed cyryllo closed 7 years ago
Hi all, I had the same error but only on one of two "almost" identical boards, except for the levels adaptation from 5V to 3V3. I'am using two boards equipped with arduino nano (operating at 5V) ad a RFM96 (SX1276) radio module (operating at 3v3) each, so I have to lower the voltage of the arduino outputs line from 5v to 3v3, as the RFM96 module isn't 5V tolerant.
The difference between the two board is that in the working one I use 4 level shifter from 5V to 3v3V for the lines MOSI, NSS, RESET, SCK, as the link below: https://www.tme.eu/it/en/details/sn74lvc1t45dckt/interfaces-others-integrated-circuits/texas-instruments/
Instead, in the not working board I adapt this voltage using 4 simple resistor divider, with 1K in series from the arduino pin and 1k8 to ground, so I obtain (5V * 1K8) / 2K8 = 3.14V on the radio module.
In this board (with resistor divider) I have the error:
FAILURE /root/Arduino/libraries/arduino-lmic-master/src/lmic/radio.c:689
but not in the first one, with level shifter, that work fine.
This error means SPI failure on reading the RegVersion register, at least in my case. To see the signal in the SPI interface on the radio I comment out this line in radio.c:
//some sanity checks, e.g., read version number
//u1_t v = readReg(RegVersion);
and add the follow line to continuosly send packed over SPI interface and check the lines with an oscilloscope:
u1_t v = 0;while (1) {v = readReg(RegVersion);}
Result: The MOSI, NSS; SCK signals are identical on the 2 boards (except for little difference in the shape of the resistor divider board, but not important at 4 Mhz), but there isn't any signal on the MISO line, because the RST line is always LOW in the board with resistor divider (and HIGH in the working one with level shifter), and this hold the radio in the reset state.
I investigate in the code, and I found a line (in radio.c)I not understand:
void radio_init () {
hal_disableIRQs();
// manually reset radio
#ifdef CFG_sx1276_radio
hal_pin_rst(0); // drive RST pin low
#else
hal_pin_rst(1); // drive RST pin high
#endif
hal_waitUntil(os_getTime()+ms2osticks(1)); // wait >100us
hal_pin_rst(2); // configure RST pin floating! <<<<<<--------- THIS LINE!
hal_waitUntil(os_getTime()+ms2osticks(5)); // wait 5ms
opmode(OPMODE_SLEEP);
// some sanity checks, e.g., read version number
u1_t v = readReg(RegVersion);
#ifdef CFG_sx1276_radio
ASSERT(v == 0x12 );
#elif CFG_sx1272_radio
ASSERT(v == 0x22);
#else
#error Missing CFG_sx1272_radio/CFG_sx1276_radio
#endif
My question is, why just before to perform a readReg operation the RST pin is set floating? I suppose that with this pin floating, if I use a level shifter I can have the pin at a high level thanks to the internal logic of the level shifter, but if I use a resistor divider the 1K8 resistor tie to ground the RST pin and hold the radio in the reset state.
I modified the code above by commenting out the line where RST pin is configured floating and driving the RST pin high before perform the SPI operation, as follow:
void radio_init () {
hal_disableIRQs();
// manually reset radio
#ifdef CFG_sx1276_radio
hal_pin_rst(0); // drive RST pin low
#else
hal_pin_rst(1); // drive RST pin high
#endif
hal_waitUntil(os_getTime()+ms2osticks(1)); // wait >100us
//hal_pin_rst(2); // configure RST pin floating!
hal_waitUntil(os_getTime()+ms2osticks(5)); // wait 5ms
hal_pin_rst(1);
opmode(OPMODE_SLEEP);
// some sanity checks, e.g., read version number
u1_t v = readReg(RegVersion);
#ifdef CFG_sx1276_radio
ASSERT(v == 0x12 );
#elif CFG_sx1272_radio
ASSERT(v == 0x22);
#else
#error Missing CFG_sx1272_radio/CFG_sx1276_radio
#endif
And now all work fine on both the boards, and solved the error.
I hope this can help someone!
bye! Cristiano
My question is, why just before to perform a readReg operation the RST pin is set floating?
The idea is that the RST pin has an internal pullup, so you just let the pullup set the right state. I guess manually driving the RST pin could also work (though it would need to be inverted for 1276), not sure why the original authors chose to do it like this.
This is intentionally, since hardware datasheet of SX127x says pins shall left floating. Look here: https://github.com/mcci-catena/arduino-lmic/issues/579
Hi all and thanks for your help. Yes, as said from cyberman54 and terrillmoore in the linked post, the problem is the resistor divider, due to the 2 k resistor to gnd that hold the chip in the RST state. The RFM96 datasheet is clear about this and it tell to left the RST floating for normal operation and drive LOW only for reset, so as terrillmoor says, the code is right and respect the datasheet. I understand that is always better use a level shifter rather than a resistor divider to adapt different voltage levels, but this is normal pratice especially for low speed SPI comunications. However I took into consideration only the delay introduced by the resistive divider in the waveform and not other complications like this. So, if I want use resistor divider instead of ic level shifter, I think is right to comment out the line where the RST line is set to floating and manually drive this pin high. Another better solultion that respect the datasheet specs, would be not use a resistive divider in the RST line but only a 1k serie resistor between arduino pin and RFM96 RST pin, to avoid any damage if accidentally the arduino pin is set to high, and left the code as the original. So I can drive low RST pin when I want reset the radio, but the floating state during operation is respected and not affected. I make this test and confirm you later if this work fine. Thank all for your time and for your work. Have a nice day! Cristiano
Yes, I confirm you that by removing the 1K8 resistor to ground in the resistive divider and left only the 1K serie resistor in the RST line from arduino to radio all work fine with the original code. Thanks!
Hi,
I hope you are doing good. I fixed this issue. Please replace this: `
ASSERT(v == 0x12 );
ASSERT(v == 0x22);
`
with this: `
if(v != 0x12 )
return 0;
if(v != 0x22)
return 0;
`
in radio.c line 688.
@guljanjua I tried this but I get an error on line 737. Do you know how can I solve it?
Hi @KaiserFels ,
I hope you are doing good. Well I solved this error but still library was not working and was not uploading data to the thingsnetwork. So I ended up using this library: https://github.com/mcci-catena/arduino-lmic
One more thing, if you are using Uno and adding GPS or any extra library that will use memory so a stability problem may occur and Arduino will send 2-3 LoRa packets and than it stop sending data. You may need to go for arduino with more memory.
I hope it will be helpful for you.
I am using TTGO v2.1 module. I used the library you posted and after selecting EU868 as the Region, I got the following error. "Error: MCCI_LoRaWAN_LMIC_library-3.0.99\src\lmic\oslmic.c:53" Now I checked the pins in getpinmap_ttgo_lora32_v2.1.cpp and it was correct. I can't find the solution.
Well I am sorry I have not tried this library on esp32. Maybe try changing pin to another pin and see if it works.
Thank for your time.
I use module sx1272 on uno and i get failure