主要内容

setGPIOAttribute

R2026b

Configure GPIO and ATR attributes

Since R2026b

Description

setGPIOAttribute(radio,bank,source,attribute,value) configures a GPIO or ATR attribute for the GPIO signals in the GPIO bank bank that are controlled by the radio source source on the radio associated with the radio object radio.

Use this function to enable ATR operation for selected GPIO signals, set signal direction, configure manual GPIO output, or define the GPIO output state for idle, receive, transmit, and full‑duplex radio states.

Note

The following actions reset the GPIO configuration:

  • Loading an application onto the radio. This occurs when you specify the Preload name-value argument as true during object creation, or the first time you call the transmit or capture function on an object created without Preload=true.

  • Calling the setup function on a usrp System object™.

  • Changing properties that select radio antennas, such as Antennas, TransmitAntennas, ReceiveAntennas, DUTInputAntennas, or DUTOutputAntennas.

  • Changing the SampleRate property to a value derived from a different master clock rate. For more information on how the baseband sample rate is derived, see Baseband Sample Rate in NI USRP Radios.

To preserve the GPIO configuration, perform these actions before you configure GPIO pins.

example

Examples

collapse all

Enable ATR operation and configure a GPIO signal as an output.

Create a radio object and select a GPIO bank, radio source, and signal index.

radio = radioConfigurations("MyRadio");
banks = getGPIOBanks(radio);
gpioBank = banks(1);
sources = getAvailableGPIOSources(radio,gpioBank);
radioSource = sources(4);
signalIndex = 5;

Resolve the attribute bank and signal index. For USRP X410 radios, use "GPIO" as the bank identifier and offset the signal index by 12 for signals on the GPIO1 connector. For details, see the bank input argument.

if strcmp(radio.Hardware,"USRP X410")
    attrBank = "GPIO";
    if strcmp(gpioBank,"GPIO1")
        attrSignalIndex = signalIndex + 12;
    else
        attrSignalIndex = signalIndex;
    end
else
    attrBank = gpioBank;
    attrSignalIndex = signalIndex;
end

Query the current attribute values, then use bitset to update only the target signal without affecting other signals in the register.

ctrlValue = getGPIOAttribute(radio,attrBank,radioSource,"CTRL");
setGPIOAttribute(radio,attrBank,radioSource,"CTRL",bitset(ctrlValue,attrSignalIndex,1));

ddrValue = getGPIOAttribute(radio,attrBank,radioSource,"DDR");
setGPIOAttribute(radio,attrBank,radioSource,"DDR",bitset(ddrValue,attrSignalIndex,1));

Input Arguments

collapse all

Radio object, specified as a radio object that corresponds to a radio setup configuration you saved using the Radio Setup wizard.

To create a radio object, call the radioConfigurations function with the name of your radio setup configuration. For example, for a radio setup configuration named MyRadio, call radio = radioConfigurations("MyRadio").

GPIO bank identifier, specified as a string scalar that identifies a GPIO bank on the radio.

To query the available GPIO bank identifiers on the radio, use the getGPIOBanks function.

Note

If you have a USRP™ X410 radio, use "GPIO" as the bank identifier.

  • Bits 1–12 of the attribute value value correspond to the "GPIO0" bank.

  • Bits 13–24 of the attribute value value correspond to the "GPIO1" bank.

Data Types: string

GPIO source identifier, specified as a string scalar that identifies which radio source controls the GPIO signals. The source identifies the FPGA radio block that owns the GPIO registers. You must specify a source for both ATR operation and manual GPIO control.

Valid values depend on the radio and the selected bank. To query the available GPIO sources for a bank, use the getAvailableGPIOSources function

Data Types: string

GPIO or ATR attribute to query, specified as a string scalar.

Attribute ValueDescription
"CTRL"

Control mode for each GPIO signal.

  • A value of 1 enables ATR control.

  • A value of 0 enables manual GPIO control.

"DDR"

Signal direction.

  • A value of 1 configures the signal as an output.

  • A value of 0 configures the signal as an input.

"OUT" GPIO output state when the signal is configured for manual GPIO control and as an output.
"ATR_0X" GPIO output state when the radio is idle.
"ATR_RX" GPIO output state when the radio is receiving.
"ATR_TX" GPIO output state when the radio is transmitting.
"ATR_XX" GPIO output state when the radio is transmitting and receiving, which is referred to as full‑duplex operation.
"READBACK" Current GPIO signal state as read from the hardware. This attribute is read‑only.

Data Types: string

GPIO or ATR attribute register value, specified as an unsigned 32‑bit integer. Each bit corresponds to one GPIO signal in the selected bank.

Individual bits in the GPIO or ATR attribute register value correspond to one GPIO signal in the specified bank.

  • The least significant bits map to the lowest‑numbered GPIO signals. For example, bit 1 corresponds to GPIO signal Data[0], bit 2 corresponds to Data[1], and so on.

  • On a USRP X410 radio, the value corresponds to both GPIO banks. Bits 1–12 correspond to the "GPIO0" bank, and bits 13–24 correspond to the "GPIO1" bank.

GPIO signal indices do not correspond directly to physical pin numbers on the connector. For details about the mapping between GPIO signals and connector pins, see GPIO Connectors and Pin Mapping.

Data Types: uint32

Version History

Introduced in R2026b