7. How to use Timer Interrupts in 1SJ LoRa Device?

In this section, we will be adding a sample "heartbeat" timer function whereby it will be used to determine if the 1SJ device is still running by printing a "Heartbeat" message every 10 seconds.
Modifying the project files in lora_app.c
Go to line 122 under the section for private function prototypes. We will create a prototype function called HeartbeatEvent by adding in the following line seen below.

|
Below the LoRaWAN_Init main code, we will define what our HeartbeatEvent function does. For our simple example, we would like it to send a message to our virtual terminal for us to determine if our application is still working. We will use the APP_LOG() function to print this message. TS_ON prints the timestamp along with our message, you can change this parameter to TS_OFF to disable the timestamp. Go to line 313 under the private functions definition area and add in the following.

| |
After defining the functions, we need to create a variable for our timer. Go to line 221 under private variables and add in the following line:

*Note: The variable is defined as HeartbeatTimer
| static UTIL_TIMER_Object_t HeartbeatTimer; //Murata - Add timer periodic counter for heartbeat |
Finally, this HeartbeatTimer will be used in LoRaWAN_Init() where we use the timer functions seen in earlier sections to create our timer function. Go to line 257 and add in the following:

|
UTIL_TIMER_Create(&HeartbeatTimer, 0xFFFFFFFFU, UTIL_TIMER_PERIODIC, HeartbeatEvent, NULL); UTIL_TIMER_SetPeriod(&HeartbeatTimer, 10000); //Murata - Units is in ms -> 10000ms = 10s UTIL_TIMER_Start(&HeartbeatTimer);
|
Essentially, the heartbeat event is repeated every ten seconds and taken care of by our HeartbeatTimer variable. Click on rebuild, load in the 1SJ device, press the reset button on the 1SJ and notice the Heartbeat function in our Tera term terminal seen below.
