初学者
10 分钟

使用4DIR1421H和PIC32MZ2048EFM100在电气隔离的部分之间实现SPI通信

四通道SPI通信数字隔离器

SPI Isolator 9 Click with Curiosity PIC32 MZ EF

已发布 1月 14, 2025

点击板

SPI Isolator 9 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

高隔离和抗噪能力的 SPI 通信,非常适合工业自动化和电机驱动系统

A

A

硬件概览

它是如何工作的?

SPI Isolator 9 Click基于来自英飞凌的4DIR1421H,这是一款四通道数字隔离器,专为严苛环境中的精确数据通信设计。该设备额定耐受隔离电压高达5700Vrms,并符合UL 1577 (Ed. 5)认证标准(认证号E311313),确保满足严格的工业安全要求。此板具有四个数据通道,提供强大的SPI隔离,是在电气隔离域之间需要可靠且安全的数据传输的系统的理想解决方案。4DIR1421H采用英飞凌的ISOFACE™ Coreless Transformer (CT)技术,具有出色的系统抗

噪能力,其最低共模瞬变抗扰度(CMTI)为100kV/µs,可在嘈杂的工业环境中确保稳定性能。它支持高达40Mbps的数据速率,允许进行高速通信,并以低功耗高效运行,有助于整体系统节能。凭借其强大的隔离能力,它非常适用于工业和电信环境中要求安全性和可靠性的开关模式电源(SMPS),以及服务器和电信系统、工业自动化、马达驱动器和医疗设备。此Click板™采用独特的设计格式,支持MIKROE新推出的“Click Snap”功能。与标准版Click板不同,此功能允许通过

折断PCB来移动主IC区域,为实现多种新功能提供了可能性。得益于Snap功能,4DIR1421H可以通过直接访问标记为1-8的引脚信号独立运行。此外,Snap部分包含指定且固定的螺丝孔位置,使用户能够将Snap板固定在所需的位置。此Click板™可以通过VCC SEL跳线选择以3.3V或5V逻辑电压运行。这样,3.3V和5V逻辑电平兼容的MCU都可以正确使用通信线。此外,该Click板™配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

SPI Isolator 9 Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
ID SEL
RA9
RST
SPI Select / ID COMM
RPD4
CS
SPI Clock
RPD1
SCK
SPI Data OUT
RPD14
MISO
SPI Data IN
RPD3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

SPI Isolator 9 Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity PIC32 MZ EF MB 1 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
Curiosity PIC32 MZ EF 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”替换为要显示的参数。

软件支持

库描述

SPI Isolator 9 Click 演示应用程序使用 NECTO Studio开发,确保与 mikroSDK 的开源库和工具兼容。该演示设计为即插即用,可与所有具有 mikroBUS™ 插座的 开发板、入门板和 mikromedia 板完全兼容,用于快速实现和测试。

示例描述
本示例演示了如何通过 SPI Isolator 9 Click 板读取连接的 Accel 22 Click 板的设备 ID。

关键功能:

  • spiisolator9_cfg_setup - 配置对象初始化函数。

  • spiisolator9_init - 初始化函数

  • spiisolator9_write - 使用 SPI 串行接口写入指定数量的数据字节。

  • spiisolator9_read - 使用 SPI 串行接口读取指定数量的数据字节。

  • spiisolator9_write_then_read - 使用 SPI 串行接口写入并读取指定数量的数据字节。

应用初始化
初始化驱动程序和日志记录器。

应用任务
读取并检查连接的 Accel 22 Click 板的设备 ID,并将结果大约每秒显示一次在 USB UART 上。

开源

代码示例

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

/*!
 * @file main.c
 * @brief SPI Isolator 9 Click example
 *
 * # Description
 * This example demonstrates the use of SPI Isolator 9 Click board by reading the
 * device ID of the connected Accel 22 Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and logger.
 *
 * ## Application Task
 * Reads and checks the device ID of the connected Accel 22 Click board, and displays the
 * results on the USB UART approximately once per second.
 *
 * @note
 * Make sure to provide a VCC power supply on the VOUT side.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "spiisolator9.h"

static spiisolator9_t spiisolator9;
static log_t logger;

/**
 * @brief SPI Isolator 9 get accel 22 id function.
 * @details This function reads and checks the device ID of the connected Accel 22 Click board.
 * @param[in] ctx : Click context object.
 * See #spiisolator9_t object definition for detailed explanation.
 * @return None.
 * @note None.
 */
void spiisolator9_get_accel22_id ( spiisolator9_t *ctx );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    spiisolator9_cfg_t spiisolator9_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.
    spiisolator9_cfg_setup( &spiisolator9_cfg );
    SPIISOLATOR9_MAP_MIKROBUS( spiisolator9_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == spiisolator9_init( &spiisolator9, &spiisolator9_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    spiisolator9_get_accel22_id ( &spiisolator9 );
    Delay_ms( 1000 );
}

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

void spiisolator9_get_accel22_id ( spiisolator9_t *ctx )
{
    #define DEVICE_NAME             "Accel 22 Click"
    #define DEVICE_SPI_READ_REG     0x0B
    #define DEVICE_REG_ID           0x00
    #define DEVICE_ID               0xAD
    uint8_t data_in[ 2 ] = { DEVICE_SPI_READ_REG, DEVICE_REG_ID };
    uint8_t device_id;
    if ( SPIISOLATOR9_OK == spiisolator9_write_then_read ( ctx, data_in, 2, &device_id, 1 ) )
    {
        log_printf( &logger, "\r\n %s\r\n", ( char * ) DEVICE_NAME );
        if ( DEVICE_ID == device_id )
        {
            log_printf ( &logger, " Device ID: 0x%.2X\r\n", ( uint16_t ) device_id );
        }
        else
        {
            log_error( &logger, " Wrong Device ID: 0x%.2X", ( uint16_t ) device_id );
        }
    }
}

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

额外支持

资源

喜欢这个项目吗?

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