lr2  2.0.0.0
Main Page

LR 2 click

LR 2 Click is a compact add-on board that contains a low-power, long-range transceiver. This board features the RN2903, RF technology-based SRD transceiver, which operates at a frequency of 915MHz from Microchip Technology. This Click boardâ„¢ features an embedded LoRaWAN Class A compliant stack, providing a long-range spread spectrum communication with high interference immunity. The RN2903 module is fully compliant with the United States (FCC) and Canada (IC) regulations combined with the advanced and straightforward command interface allowing easy integration into the final application.

click Product page


Click library

  • Author : Stefan Ilic
  • Date : Jun 2021.
  • Type : UART type

Software Support

We provide a library for the LR2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for LR2 Click driver.

Standard key functions :

  • lr2_cfg_setup Config Object Initialization function.
    void lr2_cfg_setup ( lr2_cfg_t *cfg );
  • lr2_init Initialization function.
    err_t lr2_init ( lr2_t *ctx, lr2_cfg_t *cfg );
  • lr2_default_cfg Click Default Configuration function.
    void lr2_default_cfg ( lr2_t *ctx, bool cb_default, void ( *response_p )( char *response ) );

Example key functions :

  • lr2_mac_tx Function for writing mac parameters
    uint8_t lr2_mac_tx ( lr2_t *ctx, lr2_mac_t *mac );
  • lr2_join Function for setting join mode
    uint8_t lr2_join ( lr2_t *ctx, char *join_mode, char *response );
  • lr2_tick_conf Timer Configuration
    void lr2_tick_conf ( lr2_t *ctx, uint32_t timer_limit );

Example Description

This example reads and processes data from LR 2 clicks.

The demo application is composed of two sections :

Application Init

Initializes driver init and LR 2 init.

void application_init ( void ) {
log_cfg_t log_cfg;
lr2_cfg_t cfg;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
lr2_cfg_setup( &cfg );
LR2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
lr2_init( &lr2, &cfg );
lr2_default_cfg( &lr2, 0, &lr2_cbk );
log_printf( &logger, "mac pause\r\n" );
for ( cnt = 0; cnt < 10; cnt++ ) {
log_printf( &logger, "%c", tmp_txt[ cnt ] );
}
log_printf( &logger, "\r\n" );
log_printf( &logger, "radio set wdt 0\r\n" );
log_printf( &logger, "%s\r\n", &tmp_txt[ 0 ] );
}

Application Task

Transmitter mode - sends one by one byte sequence of the desired message each second and checks if it is sent successfully. Receiver mode - displays all the received characters on USB UART.

void application_task ( void ) {
char *ptr;
lr2_process( );
#ifdef DEMO_APP_RECEIVER
rx_state = lr2_rx( &lr2, LR2_ARG_0, &tmp_txt[ 0 ] );
if ( rx_state == 0 ) {
tmp_txt[ 12 ] = 0;
ptr = ( char* )&int_data;
hex_to_int( &tmp_txt[ 10 ], ptr );
log_printf( &logger, "%c", int_data );
}
#endif
#ifdef DEMO_APP_TRANSMITTER
for ( cnt = 0; cnt < 9; cnt++ ) {
int8_to_hex( send_data, send_hex );
tx_state = lr2_tx( &lr2, &send_hex[ 0 ] );
if ( tx_state == 0 ) {
log_printf( &logger, " Response : %s\r\n", &tmp_txt[ 0 ] );
}
Delay_ms( 1000 );
}
#endif
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.LR2

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


int_data
int8_t int_data
Definition: main.c:47
lr2_join
uint8_t lr2_join(lr2_t *ctx, char *join_mode, char *response)
Function for setting join mode.
hex_to_int
void hex_to_int(char *origin, uint8_t *result)
Definition: main.c:93
LR2_ARG_0
#define LR2_ARG_0
Definition: lr2.h:62
send_data
uint8_t send_data
Definition: main.c:46
lr2_default_cfg
void lr2_default_cfg(lr2_t *ctx, bool cb_default, void(*response_p)(char *response))
LR 2 default configuration function.
LR2_MAP_MIKROBUS
#define LR2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: lr2.h:137
lr2_init
err_t lr2_init(lr2_t *ctx, lr2_cfg_t *cfg)
LR 2 initialization function.
lr2_mac_tx
uint8_t lr2_mac_tx(lr2_t *ctx, lr2_mac_t *mac)
Function for writing mac parameters.
application_task
void application_task(void)
Definition: main.c:160
tmp_txt
char tmp_txt[50]
Definition: main.c:52
lr2_cmd
void lr2_cmd(lr2_t *ctx, char *cmd, char *response)
Send command function.
cnt
uint8_t cnt
Definition: main.c:45
send_hex
char send_hex[50]
Definition: main.c:51
LR2_CMD_RADIO_SET_WDT
#define LR2_CMD_RADIO_SET_WDT
Definition: lr2.h:61
LR2_CMD_MAC_PAUSE
#define LR2_CMD_MAC_PAUSE
Definition: lr2.h:60
lr2_cfg_setup
void lr2_cfg_setup(lr2_cfg_t *cfg)
LR2 configuration object setup function.
LR2_CMD_SYS_GET_VER
#define LR2_CMD_SYS_GET_VER
LR 2 Click Commands.
Definition: lr2.h:59
lr2_tick_conf
void lr2_tick_conf(lr2_t *ctx, uint32_t timer_limit)
Timer Configuration.
lr2_mac_t
Mac object definition.
Definition: lr2.h:202
tx_state
uint8_t tx_state
Definition: main.c:49
application_init
void application_init(void)
Definition: main.c:124
lr2_cbk
void lr2_cbk(char *response)
Definition: main.c:119
lr2_cfg_t
LR 2 Click configuration object.
Definition: lr2.h:243
send_message
uint8_t send_message[9]
Definition: main.c:53
rx_state
uint8_t rx_state
Definition: main.c:48
lr2_rx
uint8_t lr2_rx(lr2_t *ctx, char *window_size, char *response)
Main receiver function
lr2_tx
uint8_t lr2_tx(lr2_t *ctx, char *buffer)
Main tnanceiver function.
lr2_t
LR 2 Click context object.
Definition: lr2.h:215