初学者
10 分钟

享受基于32001324和STM32L496AG的高效能、长距离无线通信解决方案

轻松计量:您的首选解决方案

M-BUS RF 4 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

M-BUS RF 4 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

凭借我们无线M-Bus收发器提供的创新和效率,领先于计量解决方案的世界。

A

A

硬件概览

它是如何工作的?

M-BUS RF 4 Click基于Mipot的32001324,这是一款868MHz频段的收发模块。该无线电在未授权的868 MHz SRD频段运行,指定的串行数据速率高达115.2 Kbps。这款M-BUS RF 4 Click非常适合开发各种应用,主要是水、气、热和电力计量应用,以及在仪表和集中器设备上使用。该模块支持多种操作模式(S、T、R、C),以满足固定和移动系统中单向和双向数据通信的要求。根据EN13757-4标准实现的嵌入式栈提供了对无

线M-Bus通信的物理访问。在启动时,模块读取INTERFACE_SELECTION输入引脚状态,该引脚连接到mikroBUS™插座的PWM引脚(在Click板上标记为SEL)。该引脚应保持未连接或设置为高电平以选择UART接口,或设置为低电平以选择SPI接口与主MCU进行通信。广泛使用的SPI和UART接口允许灵活集成和轻松开发客户产品。该模块符合工业温度范围-40/+85°C的所有要求。此外,该模块还根据R&TTED 1999/05/EC认

证,并符合ReACH和ROHS指令。根据EN13757-4标准在模块中实现的嵌入式栈提供了对无线M-Bus通信的物理访问。M-BUS RF 4 Click通过mikroBUS™ UART或SPI接口与目标MCU通信,额外功能由IND、SEL和RTS CS/CTS引脚提供。此Click板™设计为仅在3.3V逻辑电平下操作。在将Click板™与5V逻辑电平的MCU一起使用之前,应进行适当的逻辑电压电平转换。

M-BUS RF 4 Click hardware overview image

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

你完善了我!

配件

868MHz直角橡胶天线是一种紧凑且多功能的无线通信解决方案。在868-915MHz的频率范围内运行,确保最佳的信号接收和传输。凭借50欧姆的阻抗,它兼容各种设备和系统。该天线具有2dB增益,增强了信号强度并延长了通信范围。其垂直极化进一步提升了信号清晰度。设计上能够处理高达50W的输入功率,是各种应用的坚固选择。该天线长度仅为48mm,既隐蔽又实用。其SMA公头连接器确保与设备的安全可靠连接。无论您在使用物联网设备、远程传感器还是其他无线技术,868MHz直角天线都能提供所需的性能和灵活性,实现无缝通信。

M-BUS RF 4 Click accessories image

使用的MCU引脚

mikroBUS™映射器

Data Indicate
PA4
AN
NC
NC
RST
SPI Chip Select
PG11
CS
SPI Clock
PI1
SCK
SPI Data OUT
PD3
MISO
SPI Data IN
PI3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Communication Selection
PA0
PWM
UART RTS
PH2
INT
UART TX
PG10
TX
UART RX
PB6
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

M-BUS RF 4 Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Thermo 21 Click complete accessories setup image hardware assembly
Board mapper by product7 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
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

此库包含M-BUS RF 4 Click驱动程序的API。

关键功能:

  • mbusrf4_send_command - 在开始(报头)和结束(校验和)时计算并发送报头和校验和

  • mbusrf4_generic_write - 此函数写入特定数量的数据

  • mbusrf4_generic_read - 此函数读取最大长度的数据

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * \file
 * \brief MBusRf4 Click example
 *
 * # Description
 * This example reads and processes data from M-BUS RF 4 Clicks.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver init, reads basic information and checks communication
 *
 * ## Application Task
 *  In the RX mode it is waiting to receive data from another module...
 *  In the TX mode sends the data packet....
 *
 * ## Additional Function
 * - mbusrf4_process ( ) - The general process of collecting data and adding it to application buffer;
 *
 * - mbrusrf4_clear_buff ( void ) - Clear application buffer data;
 *
 * - mbusrf4_parser_tx ( void ) - Transmit data status parser;
 *
 * - mbusrf4_parser_rx ( uint8_t logg_type ) - Receiver data parser;
 *
 * - mbusrf4_log_data ( uint8_t log_type, uint8_t *log_buf, int32_t log_len ) - Log application buffer;
 *
 * ## Note: You can't send less then 10 data byte!
 *
 *
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "mbusrf4.h"
#include "string.h"
#include "generic_pointer.h"

#define PROCESS_COUNTER 10
#define PROCESS_RX_BUFFER_SIZE 256
#define PROCESS_PARSER_BUFFER_SIZE 256

#define LOG_HEX 0
#define LOG_STR 1
#define LOG_DEC 2

// ------------------------------------------------------------------ VARIABLES

#define DEMO_APP_RECEIVER
// #define DEMO_APP_TRANSMITER

static mbusrf4_t mbusrf4;
static log_t logger;

static char parser_buf[ PROCESS_PARSER_BUFFER_SIZE ];
static int32_t parser_cnt = 0;

static uint8_t * __generic_ptr parser_ptr;

uint8_t msg[ ] = "MikroE -  FW team";

// ------------------------------------------------------- ADDITIONAL FUNCTIONS


static void mbrusrf4_clear_buff ( void );

static void mbusrf4_parser_tx ( void );

static void mbusrf4_parser_rx ( uint8_t logg_type );

static void mbusrf4_process ( void );

static void mbusrf4_log_data ( uint8_t log_type, uint8_t *log_buf, int32_t log_len );


static void mbusrf4_process ( void )
{
    int32_t rsp_size;

    char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint16_t check_buf_cnt;
    uint8_t process_cnt = PROCESS_COUNTER;


    rsp_size = mbusrf4_generic_read( &mbusrf4, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

    if ( rsp_size > 0 )
    {
        if ( parser_cnt + rsp_size >= PROCESS_PARSER_BUFFER_SIZE )
        {
            log_info( &logger, "Buffer Overflow!" );
            mbrusrf4_clear_buff(  );
        }
        else
        {
            for( int32_t rsp_cnt = 0; rsp_cnt < rsp_size; rsp_cnt++ )
            {
                parser_buf[ parser_cnt ] = uart_rx_buffer[ rsp_cnt ];
                parser_cnt++;
                if ( parser_cnt >= parser_cnt + rsp_size )
                    break;
            }
        }
    }
}

static void mbusrf4_parser_rx ( uint8_t logg_type )
{
    const int32_t RSP_LEN = 2;
    const int32_t TIMEOUT_EXIT = 10000;
    uint8_t * __generic_ptr rsp_start;
    uint8_t full_rsp = 0;
    int32_t timeout_cnt = 0;
    int32_t rsp_len = 0;
    int32_t rsp_start_index = 0;

    for ( ; ; )
    {
        rsp_start = strchr( parser_ptr, MBUSRF4_HEADER );
        if (rsp_start != 0)
            break;
        else
            mbusrf4_process();

        timeout_cnt++;
        Delay_ms ( 1 );
        if ( timeout_cnt >= TIMEOUT_EXIT )
        {
            log_error( &logger, "TIMEOUT!( Header not found )" );
            mbrusrf4_clear_buff();
            return;
        }
    }

    timeout_cnt = 0;

    for ( ; ; )
    {
        for ( int32_t cnt = 0; cnt < parser_cnt; cnt++ )
        {
            if ( rsp_start == ( parser_ptr + cnt ) )
            {
                if ( cnt + RSP_LEN <= parser_cnt )
                {
                    rsp_start_index = cnt;
                    full_rsp = 1;
                }
                else
                    full_rsp = 0;
            }
        }

        if ( full_rsp == 1 )
            break;
        else
            mbusrf4_process();

        timeout_cnt++;
        Delay_ms ( 1 );
        if ( timeout_cnt >= TIMEOUT_EXIT )
        {
            log_error( &logger, "TIMEOUT! ( Response length not found )" );
            return;
        }
    }

    timeout_cnt = 0;

    rsp_len = ( int32_t )parser_buf[ rsp_start_index + 2 ];

    if ( rsp_len <= 0 )
    {
        mbrusrf4_clear_buff();
        return;
    }

    for ( ; ; )
    {
        if ( ( rsp_start_index + RSP_LEN + rsp_len + 1 ) <= parser_cnt )
            full_rsp = 1;
        else
            full_rsp = 0;

        if ( full_rsp == 1 )
            break;
        else
            mbusrf4_process();

        timeout_cnt++;
        Delay_ms ( 1 );
        if ( timeout_cnt >= TIMEOUT_EXIT )
        {
            log_error( &logger, "TIMEOUT! ( Response not found )" );
            return;
        }
    }

    rsp_start_index += 3;
    mbusrf4_log_data( logg_type, &parser_buf[ rsp_start_index ], rsp_len );
    mbrusrf4_clear_buff();
}

static void mbusrf4_parser_tx ( void )
{
    const int32_t RSP_LEN = 4;
    const int32_t STATUS_DIFF = 3;
    const int32_t TIMEOUT_EXIT = 5000;

    uint8_t * __generic_ptr rsp_start;
    uint8_t full_rsp = 0;
    int32_t timeout_cnt = 0;

    for ( ; ; )
    {
        rsp_start = strchr( parser_ptr, MBUSRF4_HEADER );
        if ( rsp_start != 0 )
            break;
        else
            mbusrf4_process();

        timeout_cnt++;
        Delay_ms ( 1 );
        if ( timeout_cnt >= TIMEOUT_EXIT )
        {
            log_error( &logger, "TIMEOUT!( Header not found )" );
            return;
        }
    }

    timeout_cnt = 0;

    for ( ; ; )
    {
        for ( int32_t cnt = 0; cnt < parser_cnt; cnt++ )
        {
            if ( rsp_start == ( parser_ptr + cnt ) )
            {
                if ( cnt + RSP_LEN <= parser_cnt )
                {
                    full_rsp = 1;
                }
                else
                {
                    full_rsp = 0;
                }
            }
        }

        if ( full_rsp == 1 )
            break;
        else
            mbusrf4_process();

        timeout_cnt++;
        Delay_ms ( 1 );
        if ( timeout_cnt >= TIMEOUT_EXIT )
        {
            log_error( &logger, "TIMEOUT! ( Response not found )" );
            return;
        }
    }

    rsp_start += STATUS_DIFF;

    if ( *rsp_start == 0x00 )
        log_info( &logger, "TX OK" );
    else if ( *rsp_start == 0xFF )
        log_info( &logger, "TX ERROR" );
    else
        log_error( &logger, "TX PARSER ERROR" );
}

static void mbrusrf4_clear_buff ( void )
{
    memset( parser_buf, 0, parser_cnt );
    parser_cnt = 0;
}

static void mbusrf4_log_data ( uint8_t log_type, uint8_t *log_buf, int32_t log_len )
{
    if ( LOG_HEX == log_type )
    {
        for ( int32_t data_cnt = 0; data_cnt < log_len; data_cnt++ )
        {
            log_printf( &logger, "[ 0x%.02X ]", ( int32_t )( *( log_buf + data_cnt ) ) );
        }
    }
    else if( LOG_STR == log_type )
    {
        for ( int32_t data_cnt = 0; data_cnt < log_len; data_cnt++ )
        {
            log_printf( &logger, "%c", *( log_buf + data_cnt ) );
        }
    }
    else if( LOG_DEC == log_type )
    {
        for ( int32_t data_cnt = 0; data_cnt < log_len; data_cnt++ )
        {
            log_printf( &logger, "%d", ( int32_t )( *( log_buf + data_cnt ) ) );
        }
    }
    else
    {
        log_error( &logger, "Log type error!" );
    }
    log_printf( &logger, "\r\n" );
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    mbusrf4_cfg_t cfg;

    uint8_t payload_buff[ 20 ] = { 0 };

    /**
     * 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.

    mbusrf4_cfg_setup( &cfg );
    MBUSRF4_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    mbusrf4_init( &mbusrf4, &cfg );

    parser_cnt = 0;
    parser_ptr = &parser_buf[ 0 ];
    mbusrf4_process( );
    mbrusrf4_clear_buff();

    //Command SET mode
    payload_buff[ 0 ] = MBUSRF4_SET_VALUE_IN_EEPROM_MEMORY;
    payload_buff[ 1 ] = MBUSRF4_EEPARAM_WMBUS_MODE_S2_SHORT_PREAMBLE;

    mbusrf4_send_command( &mbusrf4, MBUSRF4_CMD_SET_MODE, 2, &payload_buff[ 0 ] );
    Delay_ms ( 500 );
    mbusrf4_process( );
    mbusrf4_parser_tx();
    mbrusrf4_clear_buff();

    // Reads FW version
    mbusrf4_send_command( &mbusrf4, MBUSRF4_CMD_GET_FW_VERSION, 0, &payload_buff[ 0 ] );
    Delay_ms ( 500 );
    mbusrf4_process( );
    log_info( &logger, "FW version:" );
    mbusrf4_parser_rx( LOG_HEX );
    log_printf( &logger, "-----------------------------------------------------------\r\n" );
    mbusrf4_process( );

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

void application_task ( void )
{
    // RX App mode
    #ifdef DEMO_APP_RECEIVER

    if ( mbusrf4_get_state_ind( &mbusrf4 ) == 0 )
    {
        Delay_ms ( 100 );
        mbusrf4_process( );

        mbusrf4_parser_rx( LOG_STR );
    }

    #endif

    // TX App Mode
    #ifdef DEMO_APP_TRANSMITER

    mbusrf4_transmit_data( &mbusrf4, msg, 17 );
    Delay_ms ( 100 );
    mbrusrf4_clear_buff();
    mbusrf4_parser_tx();
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    #endif
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}


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

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。