Intermediate
30 min

Switch and multiplex I2C signals with ease using TCA9543A and STM32F415RG

Simplify I2C connections

I2C MUX 4 Click with STM32 M4 clicker

Published Sep 10, 2023

Click board™

I2C MUX 4 Click

Dev Board

STM32 M4 clicker

Compiler

NECTO Studio

MCU

STM32F415RG

Elevate your I2C communication capabilities and unlock the full potential of your connected devices with our I2C multiplexer solution

A

A

Hardware Overview

How does it work?

I2C MUX 4 Click is based on the TCA9543A, a 2-channel, bidirectional translating I2C switch from Texas Instruments. The master SCL/SDA signal pair is directed to two channels of slave devices SC0/SD0 - SC1/SD1 where either individual channel or both channels can be selected determined by the programmable control register. The TCA9543A supports interrupt signals for the Master to detect an interrupt that can result from any of the slave devices connected to the interrupt pins on the output I2C channel header. It features I2C control using a single 8-bit control register in which bits 1 and 0 control the enabling and disabling of the two switch channels of I2C data flow, it supports a reset function, hot insertion, and has all switch channels deselected during Power-Up. This Click board™ includes a low dropout linear regulator

AP7331 from Diodes Incorporated to provide the 2.45V supply voltage for the TCA9543A. When the TCA9543APWR is turned on for the first time or anytime the device needs to be reset by cycling the power supply, which means that the Power-On reset requirements must be followed to ensure the I2C bus logic is initialized properly. The TCA9543APWR can also be reset to its default conditions by using the Power-On reset feature in the event of a glitch or data corruption. I2C MUX 4 Click communicates with MCU using the standard I2C 2-Wire interface that supports Standard-Mode (100 kHz) and Fast-Mode (400 kHz) operation. The TCA9543A generates a programmable interrupt signal routed on the INT pin of the mikroBUS™ used for the Master to detect an interrupt which can result from any of the slave devices

connected to the output I2C channel pins. It also has two address pins that allow the choice of the least significant bit (LSB) of its I2C slave address which can be done by using the SMD jumper labeled as ADDR SEL, and a Reset function routed on the RST pin of the mikroBUS™ socket used to recover the TCA9543A from a bus-fault condition. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

I2C MUX 4 Click top side image
I2C MUX 4 Click bottom side image

Features overview

Development board

STM32 M4 Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4 microcontroller, the STM32F415RG from STMicroelectronics, a USB connector, LED indicators, buttons, a JTAG connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing

access anywhere and under any circumstances. Each part of the STM32 M4 Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the STM32 M4 Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for the STM32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Mini-B connection can provide up to 500mA of current, which is more than enough to operate all

onboard and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. STM32 M4 Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

STM32 M4 Clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

196608

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PB5
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PB1
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB10
SCL
I2C Data
PB11
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

I2C MUX 4 Click Schematic schematic

Step by step

Project assembly

STM32 M4 clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the STM32 M4 clicker as your development board.

STM32 M4 clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
STM32 M4 Mini B Connector Access Clicker - 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
STM32 M4 Clicker HA MCU/Select 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

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for I2C MUX 4 Click driver.

Key functions:

  • i2cmux4_get_ch_interrupt - Get channel interrupt function

  • i2cmux4_rmt_read_bytes - Generic read data function

  • i2cmux4_check_int - Check interrupt function.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief I2cMux4 Click example
 * 
 * # Description
 * This example demonstrates the use of the I2C MUX 4 Click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver, enables the click board and makes an initial log.
 * 
 * ## Application Task  
 * In this example, we read the device ID register of the connected click boards.
 * Channel 0 : 6DOF IMU 12 click [slave address: 0x68; reg: 0x00; id val.: 0x24],
 * Channel 1 : Compass 3 click   [slave address: 0x30; reg: 0x2F; id val.: 0x0C].
 * All data logs write on USB UART changes every 2 sec.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "i2cmux4.h"

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

static i2cmux4_t i2cmux4;
static log_t logger;

uint8_t rx_data;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    i2cmux4_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.

    i2cmux4_cfg_setup( &cfg );
    I2CMUX4_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    i2cmux4_init( &i2cmux4, &cfg );

    i2cmux4_power_on( &i2cmux4, I2CMUX4_ENABLE_POWER_ON );
    Delay_ms ( 100 );
    
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_ALL_DISABLE, 0x00 );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    // CH 0 - 6DOF IMU 12 click
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_0, 0x68 );
    Delay_ms ( 100 );

    i2cmux4_rmt_read_bytes( &i2cmux4, 0x00, &rx_data, 1 );
    Delay_ms ( 100 );

    log_printf( &logger, "    6DOF IMU 12 click   \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - \r\n" );
    log_printf( &logger, "       ID = 0x%.2X  \r\n", ( uint16_t ) rx_data );
    log_printf( &logger, "----------------------- \r\n" );
    Delay_ms ( 1000 );
    
    
    // CH 1 - Compass 3 click
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_1, 0x30 );
    Delay_ms ( 100 );

    i2cmux4_rmt_read_bytes( &i2cmux4, 0x2F, &rx_data, 1 );
    Delay_ms ( 100 );

    log_printf( &logger, "      Compass 3 click      \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - \r\n" );
    log_printf( &logger, "       ID = 0x%.2X \r\n ", ( uint16_t ) rx_data );
    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 
 * \brief I2cMux4 Click example
 * 
 * # Description
 * This example demonstrates the use of the I2C MUX 4 Click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver, enables the click board and makes an initial log.
 * 
 * ## Application Task  
 * In this example, we read the device ID register of the connected click boards.
 * Channel 0 : 6DOF IMU 12 click [slave address: 0x68; reg: 0x00; id val.: 0x24],
 * Channel 1 : Compass 3 click   [slave address: 0x30; reg: 0x2F; id val.: 0x0C].
 * All data logs write on USB UART changes every 2 sec.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "i2cmux4.h"

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

static i2cmux4_t i2cmux4;
static log_t logger;

uint8_t rx_data;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    i2cmux4_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.

    i2cmux4_cfg_setup( &cfg );
    I2CMUX4_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    i2cmux4_init( &i2cmux4, &cfg );

    i2cmux4_power_on( &i2cmux4, I2CMUX4_ENABLE_POWER_ON );
    Delay_ms ( 100 );
    
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_ALL_DISABLE, 0x00 );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    // CH 0 - 6DOF IMU 12 click
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_0, 0x68 );
    Delay_ms ( 100 );

    i2cmux4_rmt_read_bytes( &i2cmux4, 0x00, &rx_data, 1 );
    Delay_ms ( 100 );

    log_printf( &logger, "    6DOF IMU 12 click   \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - \r\n" );
    log_printf( &logger, "       ID = 0x%.2X  \r\n", ( uint16_t ) rx_data );
    log_printf( &logger, "----------------------- \r\n" );
    Delay_ms ( 1000 );
    
    
    // CH 1 - Compass 3 click
    i2cmux4_set_channel( &i2cmux4, I2CMUX4_SEL_CH_1, 0x30 );
    Delay_ms ( 100 );

    i2cmux4_rmt_read_bytes( &i2cmux4, 0x2F, &rx_data, 1 );
    Delay_ms ( 100 );

    log_printf( &logger, "      Compass 3 click      \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - \r\n" );
    log_printf( &logger, "       ID = 0x%.2X \r\n ", ( uint16_t ) rx_data );
    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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.