PCA9646 - Buffered 4-channel 2-wire bus switch

Description

Library for interfacing NXP PCA9646 Buffered 4-channel 2-wire bus switch

Note: The NXP PCA9546A 4-channel I2C-bus switch with reset is also supported by this library

The PCA9646 is a monolithic CMOS integrated circuit for 2-wire bus buffering and switching in applications including I2C-bus, SMBus, PMBus, and other systems based on similar principles. -) I2C interface with communication speed up to 1 MHz -) 8 user selectable addresses (chosen by chip pins) -) Each I/O is impedance isolated from all others allowing maximum capacitance on all branches -) 30 mA static sink capability on all ports -) Hysteresis on I/O increases noise immunity

OVERVIEW

PCA9646_Abstract:
This library can be used to handle the NXP PCA9646 Buffered 4-channel 2-wire bus switch.

Interfaces:
  • 1x I2C
  • 1x GPIO for reset pin (optional)

  • The NXP PCA9546A 4-channel I2C-bus switch with reset is also supported by this library

    The PCA9646 is a monolithic CMOS integrated circuit for 2-wire bus buffering and switching in applications including I2C-bus, SMBus, PMBus, and other systems based on similar principles.
  • I2C interface with communication speed up to 1 MHz
  • 8 user selectable addresses (chosen by chip pins)
  • Each I/O is impedance isolated from all others allowing maximum capacitance on all branches
  • 30 mA static sink capability on all ports
  • Hysteresis on I/O increases noise immunity

  • For more information, see the NXP website
    PCA9646_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = PCA9646_I2C_ADDR0, // I2C Address of the chip // (depends on the logic level at the chip's ADDR pins - A0/A1/A2) } new hPCA9646[TPCA9646_Handle]; // Handle to manage the PCA9646 /** * Function that is called up when the device has been prepared for the start of the application by the * "salve" function. I.e. the device is ready for proceeding with the application. */ #callback TestPCA9646() { // Temporary memory for the control register state new iControlRegister; // Inits the I2C interface catch(rM2M_I2cInit(PORT_I2C, PCA9646_CLOCK, 0)); // Inits the PCA9646 lib catch(PCA9646_Init(hPCA9646, PORT_I2C, CHIP_ADDR, 0)); // Reads the initial control register state catch(PCA9646_GetState(hPCA9646, iControlRegister, true)); #log("Current control state: %02Xh", iControlRegister); // Modify the control register to select SC0/SD0 catch(PCA9646_SelectChannels(hPCA9646, PCA9646_CHANNEL_SC0_SD0)); // Read back the current state of the control register catch(PCA9646_GetState(hPCA9646, iControlRegister, true)); #log("Current control state: %02Xh", iControlRegister); // Close the I2C interface catch(rM2M_I2cClose(PORT_I2C)); } /* Application entry point */ main(){ salve(TestPCA9646); }

    BASIC

    PCA9646_CLOCK -

    typical I2C clock speed to be used

    PCA9646_I2C_ADDRx:

    Available I2C addresses

    The corresponding I2C address must be used if the condition applies (A2 to A0):
    PCA9646_I2C_ADDR0 - 0 0 0
    PCA9646_I2C_ADDR1 - 0 0 1
    PCA9646_I2C_ADDR2 - 0 1 0
    PCA9646_I2C_ADDR3 - 0 1 1
    PCA9646_I2C_ADDR4 - 1 0 0
    PCA9646_I2C_ADDR5 - 1 0 1
    PCA9646_I2C_ADDR6 - 1 1 0
    PCA9646_I2C_ADDR7 - 1 1 1
    PCA9646_CHANNEL_x:

    Available I2C channels in the control register

    PCA9646_CHANNEL_SC0_SD0 - Enable SC0/SD0 channel
    PCA9646_CHANNEL_SC1_SD1 - Enable SC1/SD1 channel
    PCA9646_CHANNEL_SC2_SD2 - Enable SC2/SD2 channel
    PCA9646_CHANNEL_SC3_SD3 - Enable SC3/SD3 channel
    PCA9646_CHANNEL_All - Enable all channels
    PCA9646_CHANNEL_DISABLED - No channel selected (Power-up/reset default state)
    PCA9646_SCL_DIR_x:

    SCL direction

    PCA9646_SCL_DIR_INPUT - Input (default)
    PCA9646_SCL_DIR_OUTPUT - Output
    PCA9646_Init(handle[TPCA9646_Handle], i2c, addr, reset=-1)

    Initializes I2C communication with the PCA9646


    First copies the I2C port, I2C address and if provided the gpio pin for resetting the PCA9646 to the transferred empty device handle. Afterwards performs a reset of the PCA9646 if a gpio pin was provided and checks the default control register state of the PCA9646.

    handle : TPCA9646_Handle - Empty device handle for a PCA9646
    i2c : s32 - I2C interface where PCA9646 is connected to
    The I2C interface must be initialized before using rM2M_I2cInit().
    addr : s32 - I2C Address of the chip (depends on the logic level at the chip's A0-A2 pins)
    Use only the addresses specified under PCA9646_I2C_ADDRx
    gpio : s32 - GPIO pin used to reset the PCA9646
    -1 - Reset Pin of the PCA9646 is not connected to a GPIO pin
    >= 0 - GPIO pin used to reset the PCA9646 (Only GPIO pins are supported, starting with 0 for the first GPIO of the device)
    returns : s32
    OK - If successful
    ERROR - Control register is not in the default state (PCA9646_CHANNEL_DISABLED and PCA9646_SCL_DIR_INPUT).
    < OK - If another error occurs
    PCA9646_SelectChannels(handle[TPCA9646_Handle], iSelection, iDirection=PCA9646_SCL_DIR_INPUT)

    Enable I2C communication channels and set direction


    First the PCA9646 is reset if a GPIO reset pin was set during the initialisation. Afterwards the control register is set with the selected channels and direction.

    handle : TPCA9646_Handle - Device handle of a specific PCA9646 (Initialized by PCA9646_Init() )
    iSelection : s32 - Channels which should be enabled
    Use PCA9646_CHANNEL_x
    Several channels can be enabled at the same time
    iDirection : s32 - SCL direction
    Use PCA9646_SCL_DIR_x
    Selecting the SCL direction is not required for the PCA9546A
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9646_GetState(handle[TPCA9646_Handle], &iRegisterState, bool:bReadout=false)

    Get the current control register state


    Returns the current state of the control register state. If the bReadout argument is set to true, the register state is read from the PCA9646. Per default only the register state in the handle is returned, without any I2C communication.

    handle : TPCA9646_Handle - Device handle of a specific PCA9646 (Initialized by PCA9646_Init() )
    iRegisterState : s32 - Variable for storing the contents of the control register, unchanged if result < OK
    bReadout : bool - Selecting the source from which the current state of the control register is to be obtained.
    true - Read contents of the control register from the PCA9646
    false - The last known state of the control register which is stored in the handle is returned
    returns : s32
    OK - if successful
    < OK - if an error occurs

    EXPERT

    PCA9646_CLOCK_MAX -

    absolute maximum I2C clock speed

    PCA9646_Read(handle[TPCA9646_Handle], &value)

    Read PCA9646 control register


    handle : TPCA9646_Handle - Device handle of a specific PCA9646 (Initialized by PCA9646_Init() )
    value : s32 - Variable for storing the read contents of the control register, unchanged if result < OK
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9646_Write(handle[TPCA9646_Handle], value)

    Write PCA9646 control register


    handle : TPCA9646_Handle - Device handle of a specific PCA9646 (Initialized by PCA9646_Init() )
    value : s32 - The value that should be written to the control register.
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9646_Com(handle[TPCA9646_Handle], aData{}, writelen, readlen)

    Executes an I2C communication with the PCA9646. Data is first of all sent and data is then received.


    handle : TPCA9646_Handle - Device handle of a specific PCA9646 (Initialized by PCA9646_Init() )
    aData{} : u8 - Array in which the data to be sent must initially be saved. Once the data has been sent, the array is used as a memory for the data to be received.
    writelen : s32 - Number of bytes to be sent
    readlen : s32 - Number of bytes to be received
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Number of bytes to be sent >255
  • Number of bytes to be received >255
  • < OK - if an error occurs

    DEBUG

    PCA9646_Debug_Config:
    To configure debug mode add the following macro to the main.dde file.
    /** * Use this macro to configure the debug mode: * * 0: No debugging * 1: In the event of an error, the return values of the functions for accessing * the PCA9646 are issued via the console. */ #define PCA9646_DEBUG 0

    On this page

    PCA9646 - Buffered 4-channel 2-wire bus switch