I have implemented LoRaWAN using LMIC library for MSP430 as I’m memory constrained and have got it working somewhat, but I have problems with getting correct RX timings even with LMIC_setClockError to 10-50%.
The problem is that I do not have the function micros() and as I’m sleeping and waking up every 1 second, I need to use 32768Hz ACLK clock. Right now I have a divider of 2, which makes the counter go up to 16384 every second. Therefor I have set OSTICKS_PER_SEC to 16384 and I need to modify the hal_ticks() function.
The critical timing to get the RX windows is done in schedRx12 , you may manually check the result of this calculation with your OSTICKS_PER_SEC value.
You can also adjust RX_RAMPUP, it is also important because it is the time needed for the processor to prepare the frame and setup radio.
To check the timing I toggle in radio.c an extra pin after the end of transmission (in radio_irq_handler after if( flags & IRQ_LORA_TXDONE_MASK )) and just before reception (before opmode(OPMODE_RX_SINGLE);) and I check it with an external system.
The LMIC version you reference seems quite old, take a look at the modification done in MCCI one or mine if you accept C++.
Good luck with the timing it is an hard subject.
Presumably you are staying awake whilst LMIC preps & sends the payload - the internal scheduler isn’t deterministic - so you can see variations in time between telling it to send, it starting the process & then it actually transmitting.
But if you are sleeping between the end of Tx and the beginning of Rx1, then you will have your work cut out for you - probably easier to stay awake.
Also consider you need to get the radio listening for the preamble just before the Rx1 window opens, just in case the gateway has a drifty clock as well.
But mostly, anything based on Matt’s LMIC 1.5 is going to challenge & be challenged by the Network Server as it does ADR as a MAC command & that’s about it. I’ve already conversed with another TTNer today about how to configure anything less than LoRaWAN v1.0.3 to cope and the simple answer is neither of us knew.
Can you consider moving to a larger ATmega like the 4808 so you aren’t porting code over on each MCCI LMIC release?
This is a coding issue fundamental to LMIC, I’ve not read the source for a while but I thought there was some overflow calculations in there originally as on the Arduino the overflow is 1 << 32 ms aka 49 days so there should be something in there that does it already.
Most of the Hal ticks centres around the scheduler which you could remove and use a simpler delay for the Tx1 window and use @grazy’s suggestion for tracking the timing with some pin waggling. The raw.ino will give some hints on driving the LMIC bits directly and it will give you more space if you can eliminate the oslmic code.
If you’re going to do heart surgery on the library, are you able to patch in any of the MAC commands that v3 will be expecting a response to?
Out of curiosity, what made you start out with the MSP430?
You could try running the base version of the library from Matt’s repro on an Arduino so you can see what happens. I’ll retest to be sure, but I’ve seen & others have commented on this forum that they have been getting a huge number of downlinks when using 1.0.2 on LMIC. There are things that can be set on the server to tell it the config but it’s still work in progress.
It’s also been noted that TTS appears to like 1.0.3 far more.
The MCCI LMIC 3.1.0 is declared as being “Highly compliant Class A operation” and supports both 1.0.2 and 1.0.3 - if you are going to hack up a version, that may be worth investigating.