i2cmux7  2.0.0.0
Main Page

I2C MUX 7 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Jan 2022.
  • Type : I2C type

Software Support

We provide a library for the I2C MUX 7 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for I2C MUX 7 Click driver.

Standard key functions :

Example key functions :

  • i2cmux7_set_channel This function sets the desired channel active and configures its slave address.
    err_t i2cmux7_set_channel ( i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr );
  • i2cmux7_read_channel This function reads the currently selected channel value.
    err_t i2cmux7_read_channel ( i2cmux7_t *ctx, uint8_t *ch_sel );
  • i2cmux7_generic_read This function reads a desired number of data bytes starting from the selected register by using I2C serial interface.
    err_t i2cmux7_generic_read ( i2cmux7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );

Example Description

This example demonstrates the use of I2C MUX 7 click board by reading the

device ID of a 6DOF IMU 11 and Compass 3 click boards connected to the channels 0 and 7 respectfully.

The demo application is composed of two sections :

Application Init

Initializes the driver and resets the device.

void application_init ( void )
{
log_cfg_t log_cfg;
i2cmux7_cfg_t i2cmux7_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
i2cmux7_cfg_setup( &i2cmux7_cfg );
I2CMUX7_MAP_MIKROBUS( i2cmux7_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == i2cmux7_init( &i2cmux7, &i2cmux7_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
i2cmux7_reset_device ( &i2cmux7 );
log_info( &logger, " Application Task " );
}

Application Task

Reads the device ID of the connected click boards.

Channel 0 : 6DOF IMU 11 click [slave address: 0x0E; reg: 0x00; id: 0x2D], Channel 7 : Compass 3 click [slave address: 0x30; reg: 0x2F; id: 0x0C]. All data is being logged on the USB UART where you can check the device ID.

void application_task ( void )
{
uint8_t channel, device_id;
{
if ( I2CMUX7_OK == i2cmux7_read_channel ( &i2cmux7, &channel ) )
{
log_printf( &logger, " --- Channel %u --- \r\n", ( uint16_t ) ( channel & I2CMUX7_CHANNEL_NUM_MASK ) );
}
if ( I2CMUX7_OK == i2cmux7_generic_read ( &i2cmux7, DEVICE0_REG_ID, &device_id, 1 ) )
{
log_printf( &logger, " %s - Device ID: 0x%.2X \r\n\n", ( char * ) DEVICE0_NAME, ( uint16_t ) device_id );
}
Delay_ms( 1000 );
}
{
if ( I2CMUX7_OK == i2cmux7_read_channel ( &i2cmux7, &channel ) )
{
log_printf( &logger, " --- Channel %u --- \r\n", ( uint16_t ) ( channel & I2CMUX7_CHANNEL_NUM_MASK ) );
}
if ( I2CMUX7_OK == i2cmux7_generic_read ( &i2cmux7, DEVICE1_REG_ID, &device_id, 1 ) )
{
log_printf( &logger, " %s - Device ID: 0x%.2X \r\n\n", ( char * ) DEVICE1_NAME, ( uint16_t ) device_id );
}
Delay_ms( 1000 );
}
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.I2CMUX7

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


DEVICE0_NAME
#define DEVICE0_NAME
Definition: main.c:29
DEVICE1_NAME
#define DEVICE1_NAME
Definition: main.c:35
I2CMUX7_CHANNEL_NUM_MASK
#define I2CMUX7_CHANNEL_NUM_MASK
Definition: i2cmux7.h:68
I2CMUX7_MAP_MIKROBUS
#define I2CMUX7_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: i2cmux7.h:100
DEVICE1_REG_ID
#define DEVICE1_REG_ID
Definition: main.c:38
i2cmux7_cfg_setup
void i2cmux7_cfg_setup(i2cmux7_cfg_t *cfg)
I2C MUX 7 configuration object setup function.
application_task
void application_task(void)
Definition: main.c:76
i2cmux7_set_channel
err_t i2cmux7_set_channel(i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr)
I2C MUX 7 set channel function.
DEVICE0_REG_ID
#define DEVICE0_REG_ID
Definition: main.c:32
DEVICE1_SLAVE_ADDRESS
#define DEVICE1_SLAVE_ADDRESS
Definition: main.c:37
i2cmux7_init
err_t i2cmux7_init(i2cmux7_t *ctx, i2cmux7_cfg_t *cfg)
I2C MUX 7 initialization function.
i2cmux7_read_channel
err_t i2cmux7_read_channel(i2cmux7_t *ctx, uint8_t *ch_sel)
I2C MUX 7 read channel function.
i2cmux7_reset_device
void i2cmux7_reset_device(i2cmux7_t *ctx)
I2C MUX 7 reset device function.
I2CMUX7_OK
@ I2CMUX7_OK
Definition: i2cmux7.h:148
i2cmux7_t
I2C MUX 7 Click context object.
Definition: i2cmux7.h:113
DEVICE0_SLAVE_ADDRESS
#define DEVICE0_SLAVE_ADDRESS
Definition: main.c:31
application_init
void application_init(void)
Definition: main.c:44
i2cmux7_generic_read
err_t i2cmux7_generic_read(i2cmux7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
I2C MUX 7 I2C reading function.
i2cmux7_cfg_t
I2C MUX 7 Click configuration object.
Definition: i2cmux7.h:131
DEVICE0_POSITION
#define DEVICE0_POSITION
Definition: main.c:30
DEVICE1_POSITION
#define DEVICE1_POSITION
Definition: main.c:36