Main Content

ni845x

NI USB-845x connection

Since R2023a

    Description

    An ni845x object represents a connection to a NI™ USB-8451 or USB-8452 I2C/SPI Interface Device. The NI USB-845x controller can have one or more I2C peripheral devices connected to it. To configure and communicate with a peripheral device on the NI USB-845x controller, you must first create an ni845x object and then use the device function. You can connect to multiple peripheral devices with a single ni845x object. The ni845x object in MATLAB® always has the I2C controller role and cannot be used in the peripheral role.

    Note

    To use the ni845x interface, you must have the Instrument Control Toolbox™ Support Package for National Instruments™ NI-845x I2C/SPI Interface installed. For more information, see Install Instrument Control Toolbox Support Package for National Instruments NI-845x I2C/SPI Interface.

    Creation

    Description

    example

    controller = ni845x(serialNumber) creates a connection to the NI USB-8451 or USB-8452 I2C/SPI Interface Device specified by the serial number serialNumber. You can find the serial number for your NI USB-845x controller by calling ni845xlist.

    The input serialNumber sets the SerialNumber property.

    controller = ni845x(serialNumber,Name=Value) creates a connection to the NI USB-845x controller board and sets properties using one or more name-value arguments. Set the VoltageLevel, EnablePullupResistors, and OutputDriverType properties using name-value arguments as Name1=Value1,...,NameN=ValueN, where Name is the property name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the arguments does not matter.

    example

    controller = ni845x, without arguments, attempts to create a connection to the last successfully connected NI USB-845x controller board. If you have not previously connected to an NI USB-845x controller, using this syntax creates a connection to the first available controller in the ni845xlist output.

    Properties

    expand all

    This property is read-only.

    Controller board model, specified as NI USB-8451 or NI USB-8452.

    Example: controller.Model returns the model.

    Data Types: string

    This property is read-only.

    Unique alphanumeric identifier of the NI USB-845x controller board, specified as a string scalar. This property can be set only at object creation.

    Example: controller.SerialNumber returns the unique identifier of the NI USB-845x controller.

    Data Types: string

    This property is read-only.

    Digital pins available on NI USB-845x controller, specified as a string array. Connect your I2C peripheral devices to the controller using these pins. Refer to the NI USB-845x documentation for a description of each pin. Configure and communicate with these pins using configureDigitalPin, readDigitalPin, and writeDigitalPin.

    Example: controller.AvailableDigitalPins returns the digital pins of the NI USB-845x controller.

    Data Types: string

    Voltage level of all pins in volts, specified as 3.3, 1.2, 1.5, 1.8, or 2.5. For USB-8451 controllers, the only possible value is 3.3 and this property is read-only. For USB-8452 controllers, you can set the value to 1.2, 1.5, 1.8, 2.5, or 3.3.

    Example: controller.VoltageLevel = 1.2 sets the voltage level of the USB-8452 pins to 1.2 V.

    Data Types: double

    Setting to enable or disable internal pullup resistors for I2C lines, specified as a numeric or logical 1 (true) or 0 (false). For USB-8451 controllers, the only possible value is false, since it does not have any internal pullup resistors.

    Example: controller.EnablePullupResistors = true enables internal pullup resistors.

    Data Types: logical

    Driver type used when sourcing digital I/O (DIO) signals on NI USB-845x controller, specified as "push-pull" or "open-drain".

    Example: controller.OutputDriverType = "open-drain" sets the driver type to open-drain.

    Data Types: string

    This property is read-only.

    Modes of digital pins of NI USB-845x controller, specified as a table. The table has the columns Pin and Mode. Pin lists the digital pins specified by AvailableDigitalPins and Mode lists the pin mode of each of these pins as input or output.

    When you create an ni845x object, all the pins are input by default. Change pin modes using configureDigitalPin. You can read logic values from input pins using readDigitalPin and send logic level values to output pins using writeDigitalPin.

    Example: controller.DigitalPinModes returns a table with the pin modes of the digital pins on the NI USB-845x controller.

    Data Types: table

    Object Functions

    configureDigitalPinSet digital pin mode on controller
    readDigitalPinRead logic level value of digital pin on controller
    writeDigitalPinWrite logic level value to digital pin on controller
    scanI2CBusScan for I2C peripheral devices connected to controller board

    Examples

    collapse all

    Discover and connect to an NI USB-845x controller board on your machine.

    Use ni845xlist to list all available NI USB-845x controller boards connected to your machine.

    list = ni845xlist
    list = 
    
      1×2 table
    
                 Model        SerialNumber
             _____________    ____________
    
        1    "NI USB-8452"     "01F26E0A" 
    
    

    Use the value of SerialNumber to create a connection to your NI USB-845x.

    controller = ni845x(list.SerialNumber(1))
    controller = 
    
      NI845x with properties:
    
                       Model: "NI USB-8452"
                SerialNumber: "01F26E0A"
        AvailableDigitalPins: ["P0.0"    "P0.1"    "P0.2"    "P0.3"    "P0.4"    "P0.5"    "P0.6"    "P0.7"]
    
      Show all properties, functions

    You can now connect to any I2C peripheral devices on the NI USB-845x controller by using the device function.

    Connect to an NI USB-845x Interface Device and configure the pins on it.

    Connect to the NI USB-845x using its serial number. In this example, the NI USB-845x controller board that is connected to the computer has the serial number 01F26E0A.

    controller = ni845x("01F26E0A");

    View the available digital I/O (DIO) pins on the controller and their respective pin modes by using the DigitalPinModes property.

    controller.DigitalPinModes
    ans =
    
      8×2 table
    
         Pin       Mode  
        ______    _______
    
        "P0.0"    "input"
        "P0.1"    "input"
        "P0.2"    "input"
        "P0.3"    "input"
        "P0.4"    "input"
        "P0.5"    "input"
        "P0.6"    "input"
        "P0.7"    "input"
    

    Configure the DIO(0) pin, P0.0, as output.

    configureDigitalPin(controller,"P0.0","output")

    Since the DIO(0) pin is an output pin, you can now send it a logic high level using writeDigitalPin.

    Connect to an NI USB-845x controller board and scan it for connected I2C peripheral devices.

    Connect to the NI USB-845x using its serial number. In this example, the NI USB-845x controller board that is connected to the computer has a serial number 01F26E0A.

    controller = ni845x("01F26E0A");

    Make sure that your I2C peripheral devices are physically connected to the controller. Scan for connected I2C peripheral devices. The scanI2CBus function returns a list of the I2C addresses of these peripheral devices.

    i2cAddresses = scanI2CBus(controller)
    i2cAddresses = 
    
      1×2 string array
    
        "0x48"    "0x53"

    In this example, two peripheral devices are connected. You can now create a connection to one or more of them using the device function with one of the listed I2C addresses. Refer to your peripheral device's datasheet to determine its I2C address.

    Version History

    Introduced in R2023a