MSP430 LMIC library porting

Hi there,

I’m trying to port this IBM LMIC library to the MSP430 platform.
I have implemented the HAL but I’m struggling to get the timing correctly. The library is somehow working, I can see some “Receive uplink message” on the gateway dashboard once in a while or if I use the debug on the MSP430.

To count the ticks, I set up a timer using the 1MHz SMCLK with a divider of 8 and further divider of 2 in order to fire the interrupt every 1s. This way every tick is approximately 16us and OSTICKS_PER_SEC is 62500. My problem is that I don’t have the micros() function so I’m quite lost on how to proceed. I read this other topic but still no solutions.

static void hal_time_init () {
  TA0CCTL0 |= CCIE;                     
  TA0EX0 = TAIDEX_1;   // TAIDEX_1 is dividing the clock by 2
  TA0CTL |= TASSEL__SMCLK | ID__8 | MC__CONTINUOUS;     // SMCLK/8,  continuous mode
   __bis_SR_register(GIE);
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER1_A0_VECTOR))) Timer0_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  counter_tick+=1;
  TA0CCR0 += 62500; 
}

I need some help implementing the hal_ticks function. This is what I did so far:

u4_t hal_ticks () {
  volatile u4_t seconds = sec2osticks(counter_tick); 
  return (u4_t)(sec);
}

Using the debugger I can see that after the initialisation my program keep going into the hal_io_check function forever.

static void hal_io_check() {
    uint8_t GPIO_0 =  (P8IN >> 0) & 0x01; // equivalent of DigitalRead(pin)
    uint8_t GPIO_1 =  (P7IN >> 5) & 0x01;
   
    if (dio_states[0] != GPIO_0)
    {
        dio_states[0] = !dio_states[0];
        if (dio_states[0])
            radio_irq_handler(0);
    }

    if (dio_states[1] != GPIO_1)
    {
        dio_states[1] = !dio_states[1];
        if (dio_states[1])
            radio_irq_handler(1);
    }
}

All the other functions are pretty much standard SPI stuff and equal to the Arduino versions so I’m sure that the problem is in how I’m counting the ticks. I’ve been working on this porting for over 2 weeks now and at this point, I’m completely out of ideas. I would be very glad if you could give me some directions!

Stop and move on to porting the MCCI LMIC because the 6 year old IBM library is barely able to talk LoRaWAN, so even if you do get it working it will be largely incompatible with most Network Servers expectations.

Apart from that, it would seem the internal state machine is constantly polling the radio status to see if something has finished or happened - bit hard to know if this is down to the age of the library or something to do with the porting.

But If I use this library on Arduino it works ok. This is why I think there must be something wrong in my implementation. But I get you, there is no point in wasting time with an old library. Is this the MCCI LMIC library?

Does that have the core LMIC and HAL etc?

I have replaced the default HAL time code with a 32768 Hz timer - that’s the frequency MCCI LMIC uses by default.

See the post A fork to add SAMD21 standby support to LMIC

The timer initialisation code won’t help you, but you should be able to get the idea - initialise a timer at the correct frequency and make a couple of other changes.

It seems to work well.

Regards, David.

Quick update, I managed to write my own library implementation and now I can at least see the massages coming at the Gateway. My problem now is that the messages are not forwarded to the application side (live data on the TTN console is empty). At the moment I’m not listening for any downlink (the code is very simple, I just prepare the Lora packet and send it). Do I need to implement the Rx and Rx2 windows to complete a class A device and be able to see the data on the TTN console?
Best,
Mirko

You need to implement the receive windows as well as the MAC commands for a device to work correctly with TTN (v3). Anything less will result in semi DoS for the gateway(s) that receive your uplinks.
Have you looked at Loramac-node in stead of LMIC to port to your controller?