初学者
10 分钟

使用 CP2102N 和 MK64FN1M0VDC12 提升您的项目数据通信能力。

连接世界:轻松进行数据传输的 USB 到 UART 桥接器。

USB UART 3 Click with Clicker 2 for Kinetis

已发布 6月 26, 2024

点击板

USB UART 3 Click

开发板

Clicker 2 for Kinetis

编译器

NECTO Studio

微控制器单元

MK64FN1M0VDC12

我们的 USB 到 UART 通信接口桥接解决方案简化了 USB 和 UART 设备之间的数据交换,确保快速且无错误的连接。

A

A

硬件概览

它是如何工作的?

USB UART 3 Click 基于 Silicon Labs 的高度集成 USB 转 UART 接口 CP2102N。此 IC 为嵌入式应用添加 USB 到 UART 通信,一旦安装了所需驱动程序,它将注册为虚拟 COM 端口。该设备本身具有通信所需的完整堆栈,因此不需要固件来处理 UART 和 USB 之间的数据传输过程。它提供从 300bps 到 3Mbps 的数据速率范围,支持硬件流控制,拥有 512 字节长的 FIFO 缓冲区、USB 挂起和唤醒、960 字节的非易失性配置存储器(EEPROM)等。设备带有预编程的工厂设置,因此它作为虚拟 COM 端口设备工作,需安装相应的虚拟 COM 端口设备驱动程序。在这种情况下,它将提供完全符合 RS232 的虚拟 COM 端口,可以像计算机上的其他 COM 端口一样使用和配置,USB 数据在 UART 的 RX 和 TX 引脚上可用。Click board™ 的 USB 端口由 USBLC6-2SC6 保护,这是一款非常低电容的 ESD 保护 IC,并且符合 USB 2.0 标准。使用 USBXpress™ 驱动程序时,可以通过 Silicon Labs 开发的软件应用程序 Simplicity Studio 中的 Xpress Configurator 配置设备。这提供了一个图形用户界面,用于简化该设备各种参数的配置。通过将通信配置为使用硬件握手,可以利用内部 FIFO 缓冲区以提高速度和可靠性。这需要使用 RTS 

和 CTS 引脚。硬件流控制使用这些引脚来信号传递内部 FIFO 缓冲区几乎已满的状态。当 FIFO 缓冲区几乎满时,RTS 引脚将被拉到高电平。另一方面,CTS 引脚检测到这种情况,当拉到高电平时,将不再发送数据(在 CTS 引脚被驱动到高电平状态后最多发送两个字节)。通过使用硬件流控制,在高波特率下不会发生接收器溢出情况。因此,建议在 1 Mbaud 或更高波特率的通信中使用它。也支持通过 XON 和 XOFF 字符的软件握手。RTS 和 CTS 引脚分别连接到 mikroBUS™ 的 INT 和 CS 引脚。USB 挂起事件将在两个 CP2102N 引脚上指示:SUSPEND 和 SUSPEND#。当 USB 端口挂起 IC 时,这些引脚将分别被拉到低电平和高电平。SUSPEND# 线用于点亮标有 SUSP 的 LED 指示灯,而 SUSPEND 引脚连接到 mikroBUS™ 的 AN 引脚,向 MCU 指示 USB 挂起事件。这可以用于节能目的,因为在 USB 挂起事件的情况下可以关闭外部电路。该设备还具有远程唤醒功能。当 USB 端口处于挂起模式时,通过将 WAKEUP 引脚拉到低电平,CP2102N 将开始 USB 唤醒序列。请注意,操作系统必须允许这一点,通过设置适当的电源管理选项(在 Windows 操作系统中导航到属性 > 电源管理 > 允许此设

备唤醒计算机)。WAKEUP 引脚连接到 mikroBUS™ 的 PWM 引脚。WAKEUP 引脚与 GPIO3 引脚功能复用,如果不需要 WAKEUP 功能,可以重新配置它。硬件重置引脚也可用。该引脚连接到 mikroBUS™ 的 RST 引脚,将其拉到低电平将重新初始化设备。注意,SUSP LED 在上电复位或任何其他类型的复位后将点亮,在 USB 枚举序列期间。UART RX 和 TX 引脚连接到适当的 mikroBUS™ UART 引脚,用于发送(接收)从(到)主机 MCU 的 UART 类型通信。这些引脚与内部 FIFO 缓冲区交换 UART 数据。这允许 USB 收发器将数据包发送(接收)到(从)计算机并与 UART 部分交换。数据流通过两个标有 TX 和 RX 的板载 LED 指示灯指示。这些 LED 与 GPIO0 和 GPIO1 引脚功能复用,因此不建议在配置器中更改它们。Silicon Labs 提供了广泛的文档,解释其软件应用程序的操作和功能,因此如果需要更多信息,可以参考这些文档。虚拟 COM 端口驱动程序的链接在下载部分提供。根据 CP2102N 设备的可配置 PID 和 VID 值安装驱动程序。默认情况下,设备设置为虚拟 COM 端口 (VCP) USB 到 UART 桥接器。有关构建定制驱动程序的更多信息,请参考 Silicon Labs 文档。

USB UART 3 Click hardware overview image

功能概述

开发板

Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性

的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本

身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Clicker 2 for Kinetis dimensions image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

NXP

引脚数

121

RAM (字节)

262144

使用的MCU引脚

mikroBUS™映射器

USB Suspend
PB2
AN
Reset
PB11
RST
UART CTS
PC4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Wake up
PA10
PWM
UART RTS
PB13
INT
UART TX
PD3
TX
UART RX
PD2
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

USB UART 3 Click Schematic schematic

一步一步来

项目组装

Clicker 2 for PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Clicker 2 for Kinetis作为您的开发板开始。

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
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
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

实时跟踪您的结果

应用程序输出

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”替换为要显示的参数。

软件支持

库描述

该库包含用于 USB UART 3 Click 驱动程序的 API。

关键功能:

  • usbuart3_reset - 重置功能

  • usbuart3_get_susp - 设置设备模式

  • usbuart3_send_command - 发送命令功能

开源

代码示例

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

/*!
 * \file 
 * \brief UsbUart3 Click example
 * 
 * # Description
 * This example reads and processes data from USB UART 3 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and power module.
 * 
 * ## Application Task  
 * Reads data and echos it back to device and logs it to board.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "usbuart3.h"
#include "string.h"

#define PROCESS_RX_BUFFER_SIZE 500

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


static usbuart3_t usbuart3;
static log_t logger;

static int32_t rsp_size;
static char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };

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

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

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

    usbuart3_cfg_setup( &cfg );
    USBUART3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    usbuart3_init( &usbuart3, &cfg );
    
    usbuart3_reset( &usbuart3 );
}

void application_task ( void )
{
    rsp_size = usbuart3_generic_read( &usbuart3, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

    if ( rsp_size > 0 )
    {  
        usbuart3_generic_write( &usbuart3, uart_rx_buffer, rsp_size );
        log_printf( &logger, "%s", uart_rx_buffer );
        memset( uart_rx_buffer, 0, rsp_size );
    } 
}

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
/*!
 * \file 
 * \brief UsbUart3 Click example
 * 
 * # Description
 * This example reads and processes data from USB UART 3 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and power module.
 * 
 * ## Application Task  
 * Reads data and echos it back to device and logs it to board.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "usbuart3.h"
#include "string.h"

#define PROCESS_RX_BUFFER_SIZE 500

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


static usbuart3_t usbuart3;
static log_t logger;

static int32_t rsp_size;
static char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };

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

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

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

    usbuart3_cfg_setup( &cfg );
    USBUART3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    usbuart3_init( &usbuart3, &cfg );
    
    usbuart3_reset( &usbuart3 );
}

void application_task ( void )
{
    rsp_size = usbuart3_generic_read( &usbuart3, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

    if ( rsp_size > 0 )
    {  
        usbuart3_generic_write( &usbuart3, uart_rx_buffer, rsp_size );
        log_printf( &logger, "%s", uart_rx_buffer );
        memset( uart_rx_buffer, 0, rsp_size );
    } 
}

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
/*!
 * \file 
 * \brief UsbUart3 Click example
 * 
 * # Description
 * This example reads and processes data from USB UART 3 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and power module.
 * 
 * ## Application Task  
 * Reads data and echos it back to device and logs it to board.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "usbuart3.h"
#include "string.h"

#define PROCESS_RX_BUFFER_SIZE 500

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


static usbuart3_t usbuart3;
static log_t logger;

static int32_t rsp_size;
static char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };

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

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

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

    usbuart3_cfg_setup( &cfg );
    USBUART3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    usbuart3_init( &usbuart3, &cfg );
    
    usbuart3_reset( &usbuart3 );
}

void application_task ( void )
{
    rsp_size = usbuart3_generic_read( &usbuart3, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

    if ( rsp_size > 0 )
    {  
        usbuart3_generic_write( &usbuart3, uart_rx_buffer, rsp_size );
        log_printf( &logger, "%s", uart_rx_buffer );
        memset( uart_rx_buffer, 0, rsp_size );
    } 
}

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

额外支持

资源

喜欢这个项目吗?

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