Using I2C switch to connect two cameras

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using I2C switch to connect two cameras

Using I2C switch to connect two cameras

This is an example to show how to connect two cameras (with same I2C address) on the i.MX6Q board.

In this example, the I2C switch is PCA9543A. Two cameras are OV5640 & OV5645. OV5640 is connected to CSI0, and other one OV5645 is connected to MIPI.

pastedImage_0.png

The Linux BSP is L3.0.35. In the your_board.c file, add the following for pca954x.

static struct pca954x_platform_mode pca954x_modes[] = {

     {

           .adap_id = 4,

           .deselect_on_exit = true,

     },

     {

           .adap_id = 5,

           .deselect_on_exit = true,

     },

};

static struct pca954x_platform_data pca954x_data = {

     .modes = pca954x_modes,

     .num_modes = ARRAY_SIZE(pca954x_modes)

};

In this example, the I2C switch is connected to i.MX6Q’s I2C0. The I2C address of the PCA9543A is 0x70.

static struct i2c_board_info mxc_i2c0_board_info[] __initdata = {

     {

           I2C_BOARD_INFO("pca9543", 0x70),

           .platform_data = (void *)&pca954x_data,

     },

};

The channel 0 of PCA9543A is connected to the I2C of OV5645 MIPI.

static struct i2c_board_info mux_i2c4_board_info[] __initdata = {

     {

           I2C_BOARD_INFO("ov5645_mipi", 0x3c),

           .platform_data = (void *)&mipi_csi2_data,

     },

};

The channel 1 of PCA9543A is connected to the I2C of OV5640 CSI0.

static struct i2c_board_info mux_i2c5_board_info[] __initdata = {

     {

           I2C_BOARD_INFO("ov5640", 0x3c),

           .platform_data = (void *)&csi0_camera_data,

     },

};

In the board_init function, register the I2C4 and I2C5.

i2c_register_board_info(4, mux_i2c4_board_info,

                ARRAY_SIZE(mux_i2c4_board_info));

i2c_register_board_info(5, mux_i2c5_board_info,

                ARRAY_SIZE(mux_i2c5_board_info));

Select the PCA954x driver In kernel configuration

  1. In Kernel Configuration, go to Device Drivers --> I2C support --> I2C bus multiplexing support --> Multiplexer I2C Chip support  -->
  2. Select <*> Philips PCA954x I2C Mux/switches

pastedImage_11.png

%3CLINGO-SUB%20id%3D%22lingo-sub-1114162%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EUsing%20I2C%20switch%20to%20connect%20two%20cameras%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1114162%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThis%20is%20an%20example%20to%20show%20how%20to%20connect%20two%20cameras%20(with%20same%20I2C%20address)%20on%20the%20i.MX6Q%20board.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EIn%20this%20example%2C%20the%20I2C%20switch%20is%20PCA9543A.%20Two%20cameras%20are%20OV5640%20%26amp%3B%20OV5645.%20OV5640%20is%20connected%20to%20CSI0%2C%20and%20other%20one%20OV5645%20is%20connected%20to%20MIPI.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_0.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_0.png%22%20style%3D%22width%3A%20563px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F55233i4644943092DECE88%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_0.png%22%20alt%3D%22pastedImage_0.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20arial%2Chelvetica%2Csans-serif%3B%22%3EThe%20Linux%20BSP%20is%20L3.0.35.%20In%20the%20your_board.c%20file%2C%20add%20the%20following%20for%20pca954x.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Estatic%20struct%20pca954x_platform_mode%20pca954x_modes%5B%5D%20%3D%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.adap_id%20%3D%204%2C%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.deselect_on_exit%20%3D%20true%2C%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.adap_id%20%3D%205%2C%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.deselect_on_exit%20%3D%20true%2C%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Estatic%20struct%20pca954x_platform_data%20pca954x_data%20%3D%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.modes%20%3D%20pca954x_modes%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.num_modes%20%3D%20ARRAY_SIZE(pca954x_modes)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20arial%2Chelvetica%2Csans-serif%3B%22%3EIn%20this%20example%2C%20the%20I2C%20switch%20is%20connected%20to%20i.MX6Q%E2%80%99s%20I2C0.%20The%20I2C%20address%20of%20the%20PCA9543A%20is%200x70.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Estatic%20struct%20i2c_board_info%20mxc_i2c0_board_info%5B%5D%20__initdata%20%3D%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I2C_BOARD_INFO(%22pca9543%22%2C%200x70)%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.platform_data%20%3D%20(void%20*)%26amp%3Bpca954x_data%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThe%20channel%200%20of%20PCA9543A%20is%20connected%20to%20the%20I2C%20of%20OV5645%20MIPI.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Estatic%20struct%20i2c_board_info%20mux_i2c4_board_info%5B%5D%20__initdata%20%3D%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I2C_BOARD_INFO(%22ov5645_mipi%22%2C%200x3c)%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.platform_data%20%3D%20(void%20*)%26amp%3Bmipi_csi2_data%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20arial%2Chelvetica%2Csans-serif%3B%22%3EThe%20channel%201%20of%20PCA9543A%20is%20connected%20to%20the%20I2C%20of%20OV5640%20CSI0.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Estatic%20struct%20i2c_board_info%20mux_i2c5_board_info%5B%5D%20__initdata%20%3D%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I2C_BOARD_INFO(%22ov5640%22%2C%200x3c)%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.platform_data%20%3D%20(void%20*)%26amp%3Bcsi0_camera_data%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20arial%2Chelvetica%2Csans-serif%3B%22%3EIn%20the%20board_init%20function%2C%20register%20the%20I2C4%20and%20I2C5.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Ei2c_register_board_info(4%2C%20mux_i2c4_board_info%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ARRAY_SIZE(mux_i2c4_board_info))%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3Ei2c_register_board_info(5%2C%20mux_i2c5_board_info%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20%233334ca%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ARRAY_SIZE(mux_i2c5_board_info))%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ESelect%20the%20PCA954x%20driver%20In%20kernel%20configuration%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3CLI%3EIn%20Kernel%20Configuration%2C%20go%20to%20Device%20Drivers%20--%26gt%3B%20I2C%20support%20--%26gt%3B%20I2C%20bus%20multiplexing%20support%20--%26gt%3B%20Multiplexer%20I2C%20Chip%20support%26nbsp%3B%20--%26gt%3B%3C%2FLI%3E%3CLI%3ESelect%20%26lt%3B*%26gt%3B%20Philips%20PCA954x%20I2C%20Mux%2Fswitches%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_11.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_11.png%22%20style%3D%22width%3A%20356px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F55268iA43EE109BE5925BC%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_11.png%22%20alt%3D%22pastedImage_11.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
No ratings
Version history
Last update:
‎07-17-2015 01:21 AM
Updated by: