Intermediate
20 min

Receive and process signals in the 433MHz frequency band with MICRF219A and MK64FN1M0VDC12

ASK/OOK 433MHz RF receiver with with Auto-Poll and RSSI capabilities

MICRF RX 2 Click with Clicker 2 for Kinetis

Published Apr 25, 2024

Click board™

MICRF RX 2 Click

Dev. board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

Ideal for automotive and secure access systems where reliable long-distance RF communication is required.

A

A

Hardware Overview

How does it work?

MICRF RX 2 Click is based on the MICRF219A, an ASK/OOK receiver with Auto-Poll and RSSI from Microchip. This super-heterodyne, image-reject RF receiver is engineered to require only a crystal, in this case, an onboard 13.52313MHz, and a minimal set of external components for operation. As mentioned, the MICRF219A can be programmed into an Auto-polling mode via register configuration. In this mode, it monitors if there is a valid incoming RF signal while holding data output (DO pin) in a LOW logic state. In this mode, the MICRF219A also goes between the sleep and polling states. Its suitability spans across various applications, such as low-power Remote Keyless Entry (RKE), Tire Pressure Monitoring Systems (TPMS), and remote actuation systems. In terms of performance, the MICRF219A distinguishes itself with a sensitivity of

-110dBm at 1kbps and a 0.1% Bit Error Rate (BER), complemented by four selectable demodulator filter bandwidths ranging from 1625Hz to 13kHz. Filter bandwidth can be selected by placing BW SEL jumpers in a corresponding position, 0 or 1, choosing the corresponding frequency based on the truth table from the attached MICRF219A datasheet (Table 1.). This feature permits the device to accommodate bit rates as high as 20kbps (from 2.5kbps up to 20kbps). Operating on a 3.3V supply from the mikroBUS™ power rail, it is optimized for 433MHz operation, drawing a typical supply current of 6mA. The MICRF219A also has a low-power shutdown mode controllable through the SH pin, reducing the supply current to an impressive 0.1µA, alongside an RSI pin to indicate received signal strength.

Besides these pins, it also uses the mentioned DO pin as its demodulated data output pin and the CLK pin as the programmed clock input pin for programming the device in combination with the DO pin. For antenna configurations, the board allows for the use of an onboard PCB antenna specifically tuned to 433MHz or an external antenna like Rubber Angle 433MHz Antenna via an SMA connector. Selection is made possible by adjusting the capacitor C4 from position A to B near the SMA connector. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

MICRF RX 2 Click hardware overview image

Features overview

Development board

Clicker 2 for Kinetis is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

You complete me!

Accessories

Right angle 433MHz rubber antenna boasts a frequency range of 433MHz, ensuring optimal performance within this spectrum. With a 50Ohm impedance, it facilitates efficient signal transmission. The antenna's vertical polarization enhances signal reception in a specific orientation. Featuring a 1.5dB gain, it can improve signal strength to some extent. The antenna can handle a maximum input power of 50W, making it suitable for various applications. Its compact 50mm length minimizes spatial requirements. Equipped with an SMA male connector, it easily interfaces with compatible devices. This antenna is an adaptable solution for wireless communication needs, particularly when vertical polarization is crucial.

MICRF RX 2 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Received Signal Strength Monitor
PB2
AN
Shutdown
PB11
RST
ID COMM
PC4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Programmable Clock
PA10
PWM
Receiver Data Output
PB13
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

MICRF RX 2 Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 2 for Kinetis as your development board.

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker 2 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for MICRF RX 2 Click driver.

Key functions:

  • micrfrx2_enable_device - This function enables device by setting the SHD pin to low logic state

  • micrfrx2_wait_ready - This function waits for all training bytes to arrive which indicates data ready

  • micrfrx2_read_packet - This function reads data packet and stores it in a packet_buf only if the MICRFRX2_PREAMBLE bytes are received successfully

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief MICRF RX 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of MICRF RX 2 click board by reading and parsing
 * packet messages received from the transmitter.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and enables the device. 
 *
 * ## Application Task
 * Waits for a data ready indication, then reads all packet data, verifies the CRC
 * bytes in a packet, and displays its data as well as the RSSI value on the USB UART.
 *
 * @note
 * The OOK TX click board is a compatible transmitter for the MICRF RX 2 click.
 * Here are a few steps for troubleshooting if you are experiencing issues running
 * this example:
 *  - Check the MCU clock configuration, use an external oscillator instead of the MCU's
 * internal one for better accuracy on manchester data rate delay.
 *  - Measure the actual data rate on the data line and adjust the MICRFRX2_MAN_BIT_LEN_US
 * value accordingly.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "micrfrx2.h"

#define MICRFRX2_PREAMBLE       0x5AA5  /**< Packet preamble word. */

static micrfrx2_t micrfrx2;     /**< MICRF RX 2 Click driver object. */
static log_t logger;            /**< Logger object. */
static uint8_t packet_buf[ MICRFRX2_MAX_DATA_LEN + 5 ] = { 0 };  /**< Packet buffer. */

/** 
 * @brief MICRF RX 2 wait ready function.
 * @details This function waits for all training bytes to arrive which indicates data ready.
 * @param[in] ctx : Click context object.
 * See #micrfrx2_t object definition for detailed explanation.
 * @return None.
 * @note None.
 */
static void micrfrx2_wait_ready ( micrfrx2_t *ctx );

/** 
 * @brief MICRF RX 2 read packet function.
 * @details This function reads data packet and stores it in a packet_buf only if
 * the MICRFRX2_PREAMBLE bytes are received successfully.
 * @param[in] ctx : Click context object.
 * See #micrfrx2_t object definition for detailed explanation.
 * @return Number of data bytes stored in a packet_buf.
 * @note The expected packet format is as follows (MSB first, manchester IEEE 802.3):
 * TRAINING_BYTES (at least two bytes of 0xAA), PREABMLE, LEN, DATA_IN, CRC16 (calculated
 * from whole packet excluding training bytes). Training bytes are excluded from packet_buf.
 * This function must be called immediately after calling micrfrx2_wait_ready.
 */
static uint8_t micrfrx2_read_packet ( micrfrx2_t *ctx );

/** 
 * @brief Reflect bits.
 * @details This function reflects a desired number of bits in data.
 * @return Reflected data.
 * @note None.
 */
static uint16_t micrfrx2_reflect_bits( uint16_t data_in, uint8_t len );

/** 
 * @brief CRC-16/MAXIM calculation for CRC16 function.
 * @details This function calculates CRC16 with parameteres: 
 * @li @c  Width 16 bit
 * @li @c  Polynomial 0x8005 ( x16 + x15 + x2 + x0 )
 * @li @c  Initialization 0x0000
 * @li @c  Reflect input True
 * @li @c  Reflect output True
 * @li @c  Final Xor 0xFFFF
 * @li @c  Example { 69, 00 } - 0xAFD1
 * @param[in] data_buf : Array of bytes to calculate crc from.
 * @param[in] len : Number of bytes to calculate crc from.
 * @return Calculated CRC.
 * @note None.
 */
static uint16_t micrfrx2_calculate_crc16 ( uint8_t *data_buf, uint16_t len );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    micrfrx2_cfg_t micrfrx2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    micrfrx2_cfg_setup( &micrfrx2_cfg );
    MICRFRX2_MAP_MIKROBUS( micrfrx2_cfg, MIKROBUS_1 );
    if ( DIGITAL_OUT_UNSUPPORTED_PIN == micrfrx2_init( &micrfrx2, &micrfrx2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    micrfrx2_enable_device ( &micrfrx2 );

    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static float rssi_v = 0;
    static uint8_t packet_len = 0;
    static uint8_t msg_cnt = 0;
    static uint16_t crc = 0;

    log_printf( &logger, "\r\n Waiting for data ready...\r\n" );
    micrfrx2_wait_ready ( &micrfrx2 );
    packet_len = micrfrx2_read_packet ( &micrfrx2 );
    if ( packet_len )
    {
        micrfrx2_read_rssi_voltage ( &micrfrx2, &rssi_v );
        crc = ( ( uint16_t ) packet_buf[ packet_len - 2 ] << 8 ) | packet_buf[ packet_len - 1 ];
        if ( crc == micrfrx2_calculate_crc16 ( packet_buf, packet_len - 2 ) )
        {
            log_printf( &logger, " Received message: " );
            for ( msg_cnt = 0; msg_cnt < packet_buf[ 2 ]; msg_cnt++ )
            {
                log_printf( &logger, "%c", ( uint16_t ) packet_buf[ msg_cnt + 3 ] );
            }
            log_printf( &logger, "\r\n RSSI: %.1f dBm\r\n", MICRFRX2_RSSI_V_TO_DBM ( rssi_v ) );
        }
    }
    Delay_ms ( 100 );
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

static void micrfrx2_wait_ready ( micrfrx2_t *ctx )
{
    uint16_t time_cnt = 0;
    uint16_t training_high_cnt = 0;
    uint16_t training_low_cnt = 0;
    // Loop until at least two 0xAA bytes of training data is detected
    for ( ; ; )
    {
        // Measure time in steps of MICRFRX2_MAN_BIT_LEN_US / 40 for high signal
        for ( time_cnt = 0; micrfrx2_get_data_pin ( ctx ); time_cnt++ )
        {
            Delay_us ( MICRFRX2_MAN_BIT_LEN_US / 40 );
        }
        if ( time_cnt > 30 )
        {
            // Increment training_high_cnt if signal width is at least 75% of MICRFRX2_MAN_BIT_LEN_US
            training_high_cnt++;
        }
        else
        {
            // Reset counters if any invalid signal is detected
            training_high_cnt = 0;
            training_low_cnt = 0;
        }

        // Measure time in steps of MICRFRX2_MAN_BIT_LEN_US / 40 for low signal
        for ( time_cnt = 0; ( training_high_cnt > 0 ) && !micrfrx2_get_data_pin ( ctx ); time_cnt++ )
        {
            Delay_us ( MICRFRX2_MAN_BIT_LEN_US / 40 );
        }
        if ( time_cnt > 30 )
        {
            // Increment training_low_cnt if signal width is at least 75% of MICRFRX2_MAN_BIT_LEN_US
            training_low_cnt++;
        }
        else if ( ( training_high_cnt >= 8 ) && ( training_high_cnt == ( training_low_cnt + 1 ) ) )
        {
            // At least two 0xAA bytes are detected ending with shorter low signal, so break the loop here.
            // Waiting for 12.5% of MICRFRX2_MAN_BIT_LEN_US as an offset for packet reading.
            Delay_us ( MICRFRX2_MAN_BIT_LEN_US / 8 );
            break;
        }
    }
}

static uint8_t micrfrx2_read_packet ( micrfrx2_t *ctx )
{
    uint8_t byte_cnt = 0;
    uint8_t bit_cnt = 0;
    // Loop until all data bytes are received or a bad PREAMBLE word is detected
    for ( ; ; )
    {
        if ( !micrfrx2_get_data_pin ( ctx ) )
        {
            // Store data in packet_buf in manchester IEEE 802.3 format, MSB first
            packet_buf[ byte_cnt ] |= ( 0x80 >> bit_cnt );
        }
        
        if ( 8 == ++bit_cnt )
        {
            // Reset bit counter and increment byte counter if 8 bits are received
            bit_cnt = 0;
            byte_cnt++;
        }

        if ( 2 == byte_cnt )
        {
            // Two bytes are received, check PREAMBLE word
            if ( MICRFRX2_PREAMBLE != ( ( ( uint16_t ) packet_buf[ 0 ] << 8 ) | packet_buf[ 1 ] ) )
            {
                byte_cnt = 0;
                break;
            }
        }
        else if ( ( packet_buf[ 2 ] + 5 ) == byte_cnt )
        {
            // Break the loop if all packet data are received (PREAMBLE + DATA_LEN + DATA + CRC)
            break;
        }

        // Move to the next manchester clock high state by delaying for MICRFRX2_MAN_BIT_LEN_US
        Delay_us ( MICRFRX2_MAN_BIT_LEN_US );
    }
    return byte_cnt;
}

static uint16_t micrfrx2_reflect_bits( uint16_t data_in, uint8_t len )
{
    uint16_t data_out = 0;
    for ( uint16_t cnt = 0; cnt < len; cnt++ )
    {
        data_out |= ( ( data_in >> cnt ) & 1 ) << ( len - cnt - 1 );
    }
    return data_out;
}

static uint16_t micrfrx2_calculate_crc16( uint8_t *data_buf, uint16_t len )
{
    uint16_t crc16 = 0x0000;
    for ( uint16_t cnt = 0; cnt < len; cnt++ )
    {
        crc16 ^= ( micrfrx2_reflect_bits( data_buf[ cnt ], 8 ) << 8 );
        for ( uint8_t bit_cnt = 0; bit_cnt < 8; bit_cnt++ )
        {
            if ( crc16 & 0x8000 )
            {
                crc16 = ( crc16 << 1 ) ^ 0x8005;
            }
            else
            {
                crc16 <<= 1;
            }
        }
    }
    return micrfrx2_reflect_bits( crc16, 16 ) ^ 0xFFFF;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.