初学者
10 分钟

通过THVD1426和STM32F031K6体验下一代连接水平

每个字节的数据和谐:释放全双工RS485的潜力

RS485 8 Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

RS485 8 Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

通过我们的全双工 RS485 收发器增强您的网络,提供强大的实时、高速、双向数据交换解决方案,为通信可靠性树立新标准。

A

A

硬件概览

它是如何工作的?

RS485 8 Click 基于德州仪器的 THVD1426,这是一款具有自动方向控制和 ESD 保护的 RS485 收发器。THVD1426 在 A/B 上具有一个端接电阻,可以通过 TERM 跳线启用。RS485 8 Click 配有 Littelfuse 的 SM712,这是一种 600W 非对称 TVS 二极管阵列,以及端接电阻。此二极管阵列设计用于保护 RS485 应用中的非对称工作电压,从 -7V 到 

12V,从而使其免受静电放电、快速电气瞬变和雷击浪涌的损坏。二极管阵列和端接电阻都放置在 RS485 螺钉端子附近,您可以使用它将 RS485 8 Click 连接到应用的另一端。RS485 8 Click 使用 UART 接口与主 MCU 通信,常用的 UART RX 和 TX 引脚。RS485 8 Click 上的自动方向模式默认设置为启用,可以通过下拉电阻禁用。可以通过 

mikroBUS™ 插座上的 EN 引脚的高电平状态启用自动方向模式。通过启用收发器,您可以使用数据输入引脚 RX 控制驱动器和接收器。此 Click board™ 可以通过 VCC SEL 跳线选择 3.3V 或 5V 逻辑电压电平进行操作。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,此 Click board™ 配备了包含易于使用的函数和示例代码的库,可用于进一步开发。

RS485 8 Click hardware overview image

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Enable
PA11
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PA10
TX
UART RX
PA9
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

RS485 8 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 32 with STM32F031K6 MCU作为您的开发板开始。

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Board mapper by product8 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
STM32 M4 Clicker HA MCU/Select 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

软件支持

库描述

该库包含 RS485 8 Click 驱动程序的 API。

关键功能:

  • rs4858_generic_write - RS485 8 数据写入功能。

  • rs4858_generic_read - RS485 8 数据读取功能。

  • rs4858_enable_device - RS485 8 启用设备功能。

开源

代码示例

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

/*!
 * @file main.c
 * @brief RS485 8 Click Example.
 *
 * # Description
 * This example reads and processes data from RS485 8 Clicks.
 * The library also includes a function for enabling/disabling 
 * the receiver or driver and data writing or reading.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration.
 *
 * ## Application Task
 * This example demonstrates the use of the RS485 8 Click board.
 * The app sends a "MikroE" message, reads the received data and parses it.
 * Results are being sent to the UART Terminal, where you can track their changes.
 *
 * ## Additional Function
 * - static err_t rs4858_process ( void )
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "rs4858.h"

#define PROCESS_BUFFER_SIZE 200

// Comment out the line below in order to switch the application mode to receiver.
#define DEMO_APP_TRANSMITTER

static rs4858_t rs4858;
static log_t logger;

uint8_t data_buf[ 8 ] = { 'M', 'i', 'k', 'r', 'o', 'E', '\r', '\n' };

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief RS485 8 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #rs4858_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t rs4858_process ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    rs4858_cfg_t rs4858_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.
    rs4858_cfg_setup( &rs4858_cfg );
    RS4858_MAP_MIKROBUS( rs4858_cfg, MIKROBUS_2 );
    if ( UART_ERROR == rs4858_init( &rs4858, &rs4858_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    rs4858_default_cfg ( &rs4858 );
    
#ifdef DEMO_APP_TRANSMITTER
    log_info( &logger, "---- Transmitter mode ----" );
#else
    log_info( &logger, "---- Receiver mode ----" );
#endif 
    
    log_info( &logger, " Application Task " );
    Delay_ms ( 100 );
}

void application_task ( void ) 
{
#ifdef DEMO_APP_TRANSMITTER
    rs4858_generic_write( &rs4858, data_buf, strlen( data_buf ) );
    log_info( &logger, "---- Data sent ----" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#else
    rs4858_process( );
#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;
}

static err_t rs4858_process ( void ) 
{
    int32_t rx_size;
    char rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    rx_size = rs4858_generic_read( &rs4858, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        log_printf( &logger, "%s", rx_buf );
        return RS4858_OK;
    }
    return RS4858_ERROR;
}

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

额外支持

资源

喜欢这个项目吗?

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