Trouble using I2C Mux

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
AmCi_3754291
Level 2
Level 2

Hey all

I created an I2C Mux component for the PSoC 5LP To read data from 3 IMUs with the same address. I basically wrapped a channel selection function over I2C functions:

void I2C_Mux_SetChannel (uint8_t channel) {

    switch (channel){

        case 0:

            CS1_Write(0);

            CS0_Write(0);

            CyDelayUs(500);

            break;

        case 1:

            CS1_Write(0);

            CS0_Write(1);

            CyDelayUs(500);

            break;

        case 2:

            CS1_Write(1);

            CS0_Write(0);

            CyDelay(500);

            //prev_channel = 2;

            break;

        case 3:

            CS1_Write(1);

            CS0_Write(1);

            CyDelayUs(500);

            break;

      

        default:

            //CS1_Write(0);

            //CS0_Write(0);

            break;

    }

  

}

#define SET_CHANNEL(channel, func, ...) (I2C_Mux_SetChannel(channel), func(__VA_ARGS__))

This kind of works, but I'm having 2 issues:

  1. The MasterReadBuf function seems to be behaving differently when I use it - when I use blocking functions to read my IMU data I get values that make sense, when I use non blocking functions I seem to be reading 0 for gravity (even though I get no error on reading and I seem to be reading the correct data 16 Bytes);
  2. I have an issue starting the different IMUs sequentially. I can get each of the IMUs to work individually, but when I try to get them to run sequentially the number of bytes to be read for the second IMU seems to grow exponentially.

Do you guys have any ideas of what could be causing these issues?

Please find attached a workspace bundle (although it might not be easy to work with since it has FreeRTOS stuff on there), and an image that shows my I2C was trying to read 3000 bytes. The relevant files for this issue are main.c and I2C_Muxing.c

Thanks

Amilcar

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi AmCi_3754291​,

We appreciate your effort of creating a new component for I2C multiplexing. We believe that you will be able to achieve the same using our I2C component as well. Please refer to the section Internal I2C Bus Multiplexing that explains how to use the existing I2C component to be connected to multiple I2C buses.

I've created an example project for a 2:1 I2C mux which can be easily ported to 3:1 Mux by increasing the no of terminals in the mux and demux component. Let us know if this can be used for your design. Please see attached project file. The project has a PSoC 5 master connected to two PSoC 4 based I2C slaves with the same address 0x08. The PSoC master sequentially writes and reads to both the slaves using high level I2C APIs.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
1 Reply
lock attach
Attachments are accessible only for community members.
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi AmCi_3754291​,

We appreciate your effort of creating a new component for I2C multiplexing. We believe that you will be able to achieve the same using our I2C component as well. Please refer to the section Internal I2C Bus Multiplexing that explains how to use the existing I2C component to be connected to multiple I2C buses.

I've created an example project for a 2:1 I2C mux which can be easily ported to 3:1 Mux by increasing the no of terminals in the mux and demux component. Let us know if this can be used for your design. Please see attached project file. The project has a PSoC 5 master connected to two PSoC 4 based I2C slaves with the same address 0x08. The PSoC master sequentially writes and reads to both the slaves using high level I2C APIs.

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes