初学者
10 分钟

使用TCAL9538和PIC32MZ2048EFM100扩展系统中的输入/输出(I/O)引脚数量

Click Snap外形的8位I2C总线I/O扩展器

Expand 19 Click with Curiosity PIC32 MZ EF

已发布 9月 24, 2024

点击板

Expand 19 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

为各种应用添加额外的通用I/O引脚

A

A

硬件概览

它是如何工作的?

Expand 19 Click基于德州仪器的TCAL9538,这是一款8位I2C总线I/O扩展器。该Click板™为需要额外输入/输出线的应用提供了简单的解决方案,如控制开关、传感器、按钮、LED等。TCAL9538工作在3.3V,通过标准的两线I2C通信协议轻松集成到现有系统中。TCAL9538的核心是8位数据寄存器,允许用户将I/O引脚配置为输入或输出。上电或软件复位后,所有I/O默认设置为输入,但可以通过主微控制器通过配置寄存器重新配置。每个引脚的数据存储在专用的输入端口或输出端口寄存器中,主MCU可以读取。此外,通过极性反转寄存器可以调整输入端口的极性,为设计和信号解释提供灵活性。此Click板™采用独特

设计,支持MIKROE推出的“Click Snap”功能。与标准版Click板不同,该功能允许通过断开PCB使主传感器区域变为可移动状态,开辟了许多新的实现可能性。得益于Snap功能,TCAL9538可以通过直接访问标记为1-8的引脚自主运行。此外,Snap部分包含指定和固定的螺钉孔位置,允许用户将Snap板固定在所需位置。TCAL9538的一个关键功能是其Agile I/O功能,增强了I/O端口的性能。这包括可配置的输出驱动强度、可编程的上拉和下拉电阻、可锁存的输入以及可屏蔽的中断。该设备还提供可编程的开漏或推挽输出模式,使其适应各种应用需求。这些Agile I/O功能为优化设计中的功耗、速度和电磁干扰(EMI)提供了

灵活性。Expand 19 Click使用I2C接口,时钟速度高达1MHz,确保与主MCU的快速高效通信。I2C地址可以通过板载跳线轻松配置,允许多个设备在同一总线上共存。此外,该板配有中断(INT)引脚,任何输入端口状态发生变化时触发,确保对外部事件的实时响应;还包括复位(RST)引脚,用于电源循环,将设备恢复到默认状态,确保在意外问题时可靠运行和易于恢复。此Click板™只能在3.3V逻辑电平下运行。在使用具有不同逻辑电平的MCU之前,必须进行适当的逻辑电平转换。此外,该Click板™还配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

Expand 19 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
Reset
RA9
RST
ID COMM
RPD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RF13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

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

软件支持

库描述

该库包含 Expand 19 Click 驱动程序的 API。

关键功能:

  • expand19_set_pin_direction - 此函数设置选定引脚的方向。

  • expand19_set_all_pins_value - 此函数设置所有输出引脚的值。

  • expand19_read_port_value - 此函数读取所有输入引脚的值。

开源

代码示例

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

/*!
 * @file main.c
 * @brief Expand 19 Click example
 *
 * # Description
 * This example demonstrates the use of Expand 19 Click board by setting and
 * reading the port state.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration which sets 
 * the pins 0-3 as output and others as input with pull-up enabled.
 *
 * ## Application Task
 * Sets the output pins and then reads the status of all pins and 
 * displays the results on the USB UART approximately once per second.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "expand19.h"

static expand19_t expand19;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    expand19_cfg_t expand19_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.
    expand19_cfg_setup( &expand19_cfg );
    EXPAND19_MAP_MIKROBUS( expand19_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == expand19_init( &expand19, &expand19_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( EXPAND19_ERROR == expand19_default_cfg ( &expand19 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint8_t port_value = 0;
    for ( uint16_t pin_num = EXPAND19_PIN_0_MASK; pin_num <= EXPAND19_PIN_3_MASK; pin_num <<= 1 )
    {
        expand19_set_all_pins_value( &expand19, pin_num );
        
        expand19_read_port_value( &expand19, &port_value );
        log_printf( &logger, " Port status: 0x%.2X\r\n", ( uint16_t ) port_value );
        
        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;
}

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

额外支持

资源

喜欢这个项目吗?

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