通过我们的总线扩展解决方案,轻松扩展您的 I2C 启用项目的可能性,该解决方案旨在简化远程传感器、显示器和控制设备的集成。
A
A
硬件概览
它是如何工作的?
I2C Extend 2 Click 基于 NXP Semiconductor 的 PCA9615,这是一款快速模式加 (FM+) I2C 总线缓冲器,可在电气噪声环境中扩展单端 I2C 总线。它由两个用于 SCL(串行时钟)和 SDA(串行数据)的单端到差分驱动通道组成。通过相同 I2C 总线缓冲器之间的差分传输线,当信号穿过不同的电压域(如高能量电源和电动机)时,可以消除电噪声和共模偏移。这些信号可以在较低时钟速度下达到 3 米或更长的距离,同时通过板载 RJ-45 连接器通过以太网电缆(双绞线传输线电缆)保持信号完整性。PCA9615 将默认的 I2C 信号转换为四个差分信号,两个用于 SCL,两个用于 SDA。信
号方向由 I2C 协议确定,这意味着它不需要方向信号,因为这些总线缓冲器会自动设置信号流方向。额外的电路使得 PCA9615 可以用于“热插拔”应用,其中系统始终开启,但需要插入或移除模块或卡而不干扰现有信号。由于 I2C 总线侧的电源电压可能与外部 I2C 总线侧不同,因此有两个电源引脚和公共地。第一个是通过 VCC SEL 跳线选择的标准 I2C 总线侧电源,另一个是通过 VDD SEL 跳线确定的电路主要电源。I2C Extend 2 Click 使用标准 I2C 接口与 MCU 通信,在标准模式下频率最高为 100kHz,在快速模式下频率最高为 400kHz,在快速模式加 (FM+) 下频率最高为 1MHz。用
户必须小心不要超载驱动器的电流额定值,标准和快速模式为 3mA,快速模式加 (FM+) 为 30mA。此外,该 Click 板™ 具有一个使能引脚,路由到 mikroBUS™ 插座的 CS 引脚,标记为 EN,用于关闭总线缓冲器,对于故障查找、上电排序或通过隔离不需要的部分重新配置总线系统非常有用。该 Click 板™ 可以在 3.3V 或 5V 逻辑电压水平下工作,通过 VCC SEL 跳线选择。这样,3.3V 和 5V 兼容的 MCU 都能正确使用通信线路。此外,该 Click 板™ 配备了包含易于使用的函数库和示例代码的库,可用作进一步开发的参考。
功能概述
开发板
EasyAVR v7 是第七代AVR开发板,专为快速开发嵌入式应用的需求而设计。它支持广泛的16位AVR微控制器,来自Microchip,并具有一系列独特功能,如强大的板载mikroProg程序员和通过USB的在线电路调试器。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。EasyAVR v7 通过每个端口的四种不同连接器,比以往更高效地连接附件板、传感器和自定义电子产品。EasyAVR v7 开发板的每个部分
都包含了使同一板块运行最高效的必要组件。一个集成的mikroProg,一个快速的USB 2.0程序员,带有mikroICD硬件在线电路调试器,提供许多有价值的编 程/调试选项和与Mikroe软件环境的无缝集成。除此之外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括外部12V电源供应,7-12V交流或9-15V直流通过DC连接器/螺丝端子,以及通过USB Type-B(USB-B)连接器的电源。通信选项如USB-UART和RS-232也包括在内,与
广受好评的mikroBUS™标准、三种显示选项(7段、图形和基于字符的LCD)和几种不同的DIP插座一起,覆盖了广泛的16位AVR MCU。EasyAVR v7 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
AVR
MCU 内存 (KB)
64
硅供应商
Microchip
引脚数
40
RAM (字节)
4096
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
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”替换为要显示的参数。

软件支持
库描述
该库包含 I2C Extend 2 Click 驱动程序的 API。
关键功能:
i2cextend2_rmt_write
- 远程模式下的通用数据写入功能i2cextend2_rmt_read
- 远程模式下的通用数据读取功能i2cextend2_enable
- 启用扩展功能
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief I2CExtend2 Click example
*
* # Description
* This is an example which demonstrates the use of I2C Extend 2 Click board.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initialization driver enables - I2C,
* check communication with device 6DOF IMU 11 Click
* connected to the I2C Extend 2 Click ( Remote Mode ),
* set default configuration and start measurement.
*
* ## Application Task
* In this example, we read Accel and Mag axis of the connected
* 6DOF IMU 11 Click boards to the I2C Extend 2 Click ( Remote Mode )
* which is connected by a LAN cable to I2C Extend 2 Click ( Local Mode ).
* Results are being sent to the Usart Terminal where you can track their changes.
* All data logs write on USB uart changes for every 2 sec.
*
* @author Stefan Ilic
*
*/
#include "board.h"
#include "log.h"
#include "i2cextend2.h"
static i2cextend2_t i2cextend2;
static log_t logger;
int16_t axis;
void i2cextend2_6dofimu11_get_axis ( i2cextend2_t *ctx, uint8_t axis_out_reg )
{
uint16_t rx_val = 0;
rx_val = i2cextend2_rmt_read( ctx, axis_out_reg + 1 );
rx_val <<= 8;
rx_val |= i2cextend2_rmt_read( ctx, axis_out_reg );
axis = ( int16_t ) rx_val;
}
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
i2cextend2_cfg_t i2cextend2_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.
i2cextend2_cfg_setup( &i2cextend2_cfg );
I2CEXTEND2_MAP_MIKROBUS( i2cextend2_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == i2cextend2_init( &i2cextend2, &i2cextend2_cfg ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
i2cextend2_enable( &i2cextend2, I2CEXTEND2_EXTEND_ENABLE );
if ( C6DOFIMU11_WHO_AM_I_WIA_ID == i2cextend2_rmt_read( &i2cextend2, C6DOFIMU11_REG_WHO_AM_I ) )
{
log_printf( &logger, " SUCCESS \r\n" );
log_printf( &logger, "------------------------\r\n" );
}
else
{
log_printf( &logger, " ERROR \r\n" );
log_printf( &logger, " Reset the device \r\n" );
log_printf( &logger, "------------------------\r\n" );
for ( ; ; );
}
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_CNTL2, C6DOFIMU11_CNTL2_TEMP_EN_STANDBY_MODE |
C6DOFIMU11_CNTL2_MAG_EN_STANDBY_MODE |
C6DOFIMU11_CNTL2_ACCEL_EN_STANDBY_MODE );
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_INC3, C6DOFIMU11_INC3_IEL2_FIFO_TRIG |
C6DOFIMU11_INC3_IEL1_FIFO_TRIG );
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_CNTL2, C6DOFIMU11_CNTL2_GSEL_8G |
C6DOFIMU11_CNTL2_RES_MAX2 |
C6DOFIMU11_CNTL2_MAG_EN_OPERATING_MODE |
C6DOFIMU11_CNTL2_ACCEL_EN_OPERATING_MODE );
Delay_ms ( 100 );
log_info( &logger, " Application Task " );
log_printf( &logger, "------------------------\r\n" );
}
void application_task ( void )
{
log_printf( &logger, "\t Accel \t|\t Mag \r\n" );
log_printf( &logger, "------------------------------------------------\r\n" );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_XOUT_L );
log_printf( &logger, "\t Accel X: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_XOUT_L );
log_printf( &logger, "\t Mag X: %d\r\n", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_YOUT_L );
log_printf( &logger, "\t Accel Y: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_YOUT_L );
log_printf( &logger, "\t Mag Y: %d\r\n", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_ZOUT_L );
log_printf( &logger, "\t Accel Z: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_ZOUT_L );
log_printf( &logger, "\t Mag Z: %d\r\n", axis );
log_printf( &logger, "------------------------------------------------\r\n" );
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
/*!
* @file main.c
* @brief I2CExtend2 Click example
*
* # Description
* This is an example which demonstrates the use of I2C Extend 2 Click board.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initialization driver enables - I2C,
* check communication with device 6DOF IMU 11 Click
* connected to the I2C Extend 2 Click ( Remote Mode ),
* set default configuration and start measurement.
*
* ## Application Task
* In this example, we read Accel and Mag axis of the connected
* 6DOF IMU 11 Click boards to the I2C Extend 2 Click ( Remote Mode )
* which is connected by a LAN cable to I2C Extend 2 Click ( Local Mode ).
* Results are being sent to the Usart Terminal where you can track their changes.
* All data logs write on USB uart changes for every 2 sec.
*
* @author Stefan Ilic
*
*/
#include "board.h"
#include "log.h"
#include "i2cextend2.h"
static i2cextend2_t i2cextend2;
static log_t logger;
int16_t axis;
void i2cextend2_6dofimu11_get_axis ( i2cextend2_t *ctx, uint8_t axis_out_reg )
{
uint16_t rx_val = 0;
rx_val = i2cextend2_rmt_read( ctx, axis_out_reg + 1 );
rx_val <<= 8;
rx_val |= i2cextend2_rmt_read( ctx, axis_out_reg );
axis = ( int16_t ) rx_val;
}
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
i2cextend2_cfg_t i2cextend2_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.
i2cextend2_cfg_setup( &i2cextend2_cfg );
I2CEXTEND2_MAP_MIKROBUS( i2cextend2_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == i2cextend2_init( &i2cextend2, &i2cextend2_cfg ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
i2cextend2_enable( &i2cextend2, I2CEXTEND2_EXTEND_ENABLE );
if ( C6DOFIMU11_WHO_AM_I_WIA_ID == i2cextend2_rmt_read( &i2cextend2, C6DOFIMU11_REG_WHO_AM_I ) )
{
log_printf( &logger, " SUCCESS \r\n" );
log_printf( &logger, "------------------------\r\n" );
}
else
{
log_printf( &logger, " ERROR \r\n" );
log_printf( &logger, " Reset the device \r\n" );
log_printf( &logger, "------------------------\r\n" );
for ( ; ; );
}
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_CNTL2, C6DOFIMU11_CNTL2_TEMP_EN_STANDBY_MODE |
C6DOFIMU11_CNTL2_MAG_EN_STANDBY_MODE |
C6DOFIMU11_CNTL2_ACCEL_EN_STANDBY_MODE );
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_INC3, C6DOFIMU11_INC3_IEL2_FIFO_TRIG |
C6DOFIMU11_INC3_IEL1_FIFO_TRIG );
i2cextend2_rmt_write ( &i2cextend2, C6DOFIMU11_REG_CNTL2, C6DOFIMU11_CNTL2_GSEL_8G |
C6DOFIMU11_CNTL2_RES_MAX2 |
C6DOFIMU11_CNTL2_MAG_EN_OPERATING_MODE |
C6DOFIMU11_CNTL2_ACCEL_EN_OPERATING_MODE );
Delay_ms ( 100 );
log_info( &logger, " Application Task " );
log_printf( &logger, "------------------------\r\n" );
}
void application_task ( void )
{
log_printf( &logger, "\t Accel \t|\t Mag \r\n" );
log_printf( &logger, "------------------------------------------------\r\n" );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_XOUT_L );
log_printf( &logger, "\t Accel X: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_XOUT_L );
log_printf( &logger, "\t Mag X: %d\r\n", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_YOUT_L );
log_printf( &logger, "\t Accel Y: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_YOUT_L );
log_printf( &logger, "\t Mag Y: %d\r\n", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_ACCEL_ZOUT_L );
log_printf( &logger, "\t Accel Z: %d\t|", axis );
i2cextend2_6dofimu11_get_axis( &i2cextend2, C6DOFIMU11_REG_MAG_ZOUT_L );
log_printf( &logger, "\t Mag Z: %d\r\n", axis );
log_printf( &logger, "------------------------------------------------\r\n" );
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