SPI Master Interface

Most of the DLN adapters support the SPI master interface. Some of them have several independent SPI master ports.

Before transmitting data, you need to configure the SPI master ports according to the slave requirements and enable it (See Configuring the SPI Master Interface).

You can either transmit data in full-duplex or in half-duplex mode (See SPI Data Transmission).

If you need to work with multi slave devices, you can interconnect them following the instructions in Connecting Multiple Slave Devices.

Rating: 
Средняя: 2.5 (4 оценок)

Configuring the SPI Master Interface

For reliable SPI communication, you have to configure the SPI master interface according to the SPI slave requirements:

  1. Configure the clock (SCK) signal, using a frequency, which does not exceed the maximum frequency that the slave device supports. For details, read Clock Frequency.

  2. Configure the transmission mode (clock polarity and clock phase). The clock polarity (CPOL) and clock phase (CPHA) configuration must be the same for both SPI master and SPI slave devices. For details, read Clock Phase and Polarity.

  3. Configure the frame size. The frame size instructs the DLN adapter how to treat data inside the buffer. The data can be treated as 8-16 bit integers. If the configured frame size exceeds 8 bits, the bytes inside the frame are stored in Little Endian format. For details, read SPI Data Frames.

  4. Customize releasing the SS line between frames. Some slave devices require the signal in the SS line going LOW to initiate data transmission. When the frame transmission is complete, the master should pull the SS line HIGH and then LOW again to reinitiate the frame transmission with the same slave. This parameter is optional. For details, read SS Line Release Between Frames.

  5. If a slave device needs additional time to process or generate data, configure delays. For details, read SPI Delays.

DLN-1 and DLN-2 adapters do not allow changing the SPI configuration after the SPI master port is enabled. Therefore, if you use any of these adapters, first configure the SPI master port and then enable it.

To start communication, you need to select the slave. Dropping the signal on an SS line initiates data transmission between the master and the appropriate slave device. The Connecting Multiple Slave Devices section describes possible configurations. You can select a slave device before or after enabling the SPI master port.

Rating: 
Средняя: 5 (2 оценок)

SPI Data Frames

SPI bus allows continuous data transmission. When you pass a buffer (array of words) to one of the SPI Master Transmission Functions, the DLN adapter transmits the data bit after bit as in the following figure.

SPI Data Transmission

Logically, your application and an SPI slave device treat this data as an array of 8-bit or 16-bit words. Some SPI slave devices (for example, digital-to-analog or analog-to-digital converters) operate with 12-bit words.

DLN adapters allow you to support a wide range of SPI slave devices. You can configure the frame size (number of bits in the word) by using the DlnSpiMasterSetFrameSize() function. DLN adapters support 8 to 16 bits per frame.

SPI 8 bits per frame

SPI 16 bits per frame

In DLN adapters, the frame data is transmitted in a Little Endian format (starting from the most-significant bit and up to the least-significant bit). If the frame size is not a multiple of 8, the unused (most-significant) bits are discarded, regardless of their content.

You want to transmit an array with the following data: ABCDEF01

If the frame size is 8 bits, the transmission proceeds as four 8-bit words: AB CD EF 01

SPI 8-bit transmission

If the frame size is 16 bits, the transmission proceeds as two 16-bit words. Each word is stored in the array in little endian format: CDAB 01EF

SPI 16-bit transmission

If the frame size is 12 bits, the transmission proceeds as two 12-bit words. This frame is not a multiple of 8, so the unused (most-significant) bits of the second byte in each word are discarded: ABC EF0.

Each word is stored in the array in little endian format: CAB 0EF

SPI 12-bit transmission

To transmit data as arrays of more than 8 bits, you can use the DlnSpiMasterReadWrite16() function. It transmits data in little endian format that is very useful because most microcontrollers store data in this format.

For information about all functions that you can use to transmit data, read the SPI Master Transmission Functions section.

Rating: 
Средняя: 3 (4 оценок)

SS Line Release Between Frames

By default, if an array of several frames is transmitted between the master and the same slave, the SS line stays enabled until data transmission completes.

SPI transmission

However, some SPI slave devices require the SS line to be deasserted between frames.

SPI released SS line

To release the SS line, use the DlnSpiMasterReleaseSS(). Use the DlnSpiMasterSSEnable() function to enable the SS line.

DLN-1 and DLN-2 adapters do not support the SS line release between frames.

If an SPI slave device is not fast enough to process continuously incoming data, you can configure your DLN adapter to introduce a specified delay between frames. For more information about this and other delays, read SPI Delays.

Rating: 
Средняя: 1 (1 оценка)

Clock Frequency

SPI bus can operate at very high speeds, which may be too fast for some slave devices. To accommodate such devices, the SPI bus contains the clock (CLK). The signal on the SCK line is transmitted with the same frequency as data flows. Thus, there is no need to synchronize the transmission speed of master and slave devices.

To configure the clock signal of the master, use the DlnSpiMasterSetFrequency() function.

When configuring the SPI master interface, you specify the frequency value supported by the slave device. If the specified value is not compatible with your DLN adapter, the function approximates the value to the closest lower frequency value supported by the adapter.

A range of supported clock frequency values depends on the DLN adapter:

  • DLN-1 adapters support clock frequency from 2kHz up to 4MHz.

  • DLN-2 adapters support clock frequency from 2kHz up to 18MHz.

  • DLN-4 adapters support clock frequency from 376kHz up to 48MHz.

In addition to setting the clock frequency, the master also configures the clock polarity (CPOL) and clock phase (CPHA). For detailed information, read Clock Phase and Polarity.

Rating: 
Средняя: 5 (2 оценок)

Clock Phase and Polarity

The master configures the clock polarity (CPOL) and clock phase (CPHA) to correspond to slave device requirements. These parameters determine when the data must be stable, when it should be changed according to the clock line and what the clock level is when the clock is not active.

The CPOL parameter assigns the clock level when the clock is not active. The clock (SCK) signal may be inverted (CPOL=1) or non-inverted (CPOL=0). For the inverted clock signal, the first clock edge is falling. For the non-inverted clock signal, the first clock edge is rising.

The CPHA parameter is used to shift the capturing phase. If CPHA=0, the data are captured on the leading (first) clock edge, regardless of whether that clock edge is rising or falling. If CPHA=1, the data are captured on the trailing (second) clock edge; in this case, the data must be stable for a half cycle before the first clock cycle.

There are four possible modes that can be used in an SPI protocol:

  1. For CPOL=0, the base value of the clock is zero. For CPHA=0, data are captured on the clock’s rising edge and data are propagated on a falling edge.

    CPOL=0, CPHA=0

  2. For CPOL=0, the base value of the clock is zero. For CPHA=1, data are captured on the clock’s falling edge and data are propagated on a rising edge.

    CPOL=0, CPHA=1

  3. For CPOL=1, the base value of the clock is one. For CPHA=0, data are captured on the clock’s rising edge and data are propagated on a falling edge.

    CPOL=1, CPHA=0

  4. For CPOL=1, the base value of the clock is one. For CPHA=1, data are captured on the clock’s falling edge and data are propagated on a rising edge.

    CPOL=1, CPHA=1

In DLN adapters, the default transmission mode configuration has CPOL=0, CPHA=0 values.

You can specify the mode using the DlnSpiMasterSetMode() function. To configure the CPOL and CPHA values separately, use the DlnSpiMasterSetCpol() and DlnSpiMasterSetCpha() functions.

The master and a slave must use the same set of parameters (clock frequency, CPOL and CPHA); otherwise, a communication will be impossible. If multiple slaves are used, the master configuration should change each time before the master initiates communication with a different slave.

Rating: 
Средняя: 4.4 (18 оценок)

SPI Data Transmission

DLN adapters can operate in the following modes:

  • Full-duplex – the master sends data to a slave and receives data from the slave simultaneously.

  • Half-duplex (read) – the master receives data from a slave.

  • Half-duplex (write) – the master sends data to a slave.

Rating: 
Голосов пока нет

Full-duplex communication

A full-duplex data transmission occurs during each SPI clock cycle: the master transmits data to the slave on the MOSI line and the slave receives it; at the same time, the slave transmits data to the master on the MISO line and the master receives it.

SPI Full-diplex Communication

To transmit data in a full-duplex mode, use the DlnSpiMasterReadWrite() function (for 8-bit frames) or the DlnSpiMasterReadWrite16() function (for 9-16-bit frames).

Transmission may continue for any number of clock cycles. When complete, the master idles the clock and releases the SS line. Using the DlnSpiMasterReadWriteEx() function, you can configure whether to release SS line after the transmission or to leave it on the low level.

The DlnSpiMasterReadWriteSS() function allows to select the SS line, transmit data and release the SS line. For details, read Connecting Multiple Slave Devices.

Rating: 
Голосов пока нет

Half-duplex (read) communication

In a half-duplex read mode, the slave transmits data on the MISO line and the master receives it. The MOSI line remains inactive.

SPI Half-duplex read communication

To receive data in a half-duplex mode, use the DlnSpiMasterReadEx() function. This function allows to configure whether the SS line should be released after the transmission or left on the low level.

Rating: 
Голосов пока нет

Half-duplex (write) communication

In a half-duplex write mode, the master sends data on the MOSI line and the slave receives it. The MISO line remains inactive.

SPI Half-duplex write communication

To send data in a half-duplex mode, use the DlnSpiMasterWriteEx() function. This function allows to configure whether the SS line should be released after the transmission or left on the low level.

In a half-duplex mode, the master can send data to multiple slaves simultaneously. For details, read Connecting Multiple Slave Devices.

Rating: 
Голосов пока нет

Connecting Multiple Slave Devices

In SPI, a master can communicate with a single or multiple slaves. For applications using multiple slaves, the following configurations are possible:

  1. Independent slaves. This is a most common configuration of the SPI bus. The MOSI, MISO and SCK lines of all slaves are interconnected. The SS line of every slave device is connected to a separate pin of SPI master device. Since the MISO pins of the slaves are connected together, they are required to be tristate pins (high, low or high-impedance).

    SPI Independent multiple slaves

    To select the slave, the master pulls the corresponding SS line low. Only one slave can be selected.

    For DLN-1 or DLN-2 adapters, you can use the following functions:

    DlnSpiMasterSetSS()

    to select the SS line. The SS line value can include only one bit set to 0;

    DlnSpiMasterReadWrite()

    to transmit data to/from the slave device;

    DlnSpiMasterReleaseSS()

    to release the SS line after transmission if the master does not need to transmit more data to the same slave.

    For a DLN-4M adapter, use the DlnSpiMasterReadWriteSS() function – it selects the specified SS line, transmits data and releases the SS line.In a half-duplex read mode, you can also select only one slave. The following functions can be used:

    DlnSpiMasterSetSS()

    to select the SS line. The SS line value can include only one bit set to 0;

    DlnSpiMasterReadEx()

    to read data from the slave device and to release the SS line after transmission if required.

  2. Independent slave configuration with decoder/demultiplexer. The SS lines are used to send an n-bit value, which is the number of the selected slave. Here, the master can communicate with m=2n slaves.

    SPI with Decoder

    If you use this configuration, in the DlnSpiMasterSetSS() function the value of the SS lines can include more than one zeros. The demultiplexer converts this value and activates only one SS line.

  3. Half-duplex write configuration. The master transmits data on the MOSI line and the slave receives it. The MISO line remains inactive.

    SPI Multi Slave Half-duplex Write

    If your slave devices only receive data, you can address multi slaves simultaneously. The following functions can be used:

    DlnSpiMasterSetSS()

    to select the SS line; the SS line value can include more than one bits set to 0 (several SS lines can be selected – the master can send data to several slave devices simultaneously);

    DlnSpiMasterWriteEx()

    to write data from the slave device(s) and to release the SS line(s) after transmission (optionally).

    If the master always sends equal data to some group of slaves in a half-duplex write configuration, all the slaves from the group can be connected to one SS line:

    SPI Half-duplex write multi slave on one SS

  4. Daisy-chain slaves: the first slave output is connected to the second slave input, etc. The SPI port of each slave is designed to send out during the second group of clock pulses an exact copy of the data it received during the first group of clock pulses.

    SPI Daisy-chain

In DLN-series adapters, you can use unengaged GPIO pins as slave select (SS) lines. In this case, you can control such pins with the GPIO module.

To check the number of available SS lines in the SPI port, use the DlnSpiMasterGetSSCount() function.

To select the slave, use the DlnSpiMasterSetSS() function. By default, the first SS line (SS0) is selected.

Only one slave can be activated (the signal level on the SS line is low). However, if you use a demultiplexer, you do not select the line, but set the value of the line. The demultiplexer converts this value and selects only one SS line.

The DlnSpiMasterEnable() function enables the selected SS line. Use this function after you configure communication settings.

If you do not need to use all SS lines available in a SPI port, you can disable some of them to use them in other modules. On the contrary, you can enable SS lines that were used for other modules. To disable one SS line, use the DlnSpiMasterSSDisable() function. To disable several SS lines, use the DlnSpiMasterSSMultiDisable() function. To enable one or more SS lines, use the DlnSpiMasterSSEnable() or DlnSpiMasterSSMultiEnable() function accordingly.

Rating: 
Средняя: 4.7 (3 оценок)

SPI Delays

Sometimes slave devices need additional time to process data. In order to provide this time, DLN-series adapters can insert delays at different data transmission stages:

  • Delay between data frames;

  • Delay after slave selection;

  • Delay between slave selections.

All of the delays are set in nanoseconds (ns) and are configured only once. The defined delay values are the same for all SS lines of the port.

DLN-1 and DLN-2 adapters do not support SPI delays.
Rating: 
Средняя: 5 (1 оценка)

Delay between data frames

In case a slave device is not fast enough to process continuously incoming data, you can configure the DLN adapter to insert delays between each two consecutive frames. This gives the slave device additional time to process the data from the previous frame. Once enabled, the delay is inserted after each frame.

SPI Delay Between Frames

The default value of the delay between frames is 0ns. The delay value is adjusted using the DlnSpiMasterSetDelayBetweenFrames() function. The current delay between frames value can be retrieved by calling the DlnSpiMasterGetDelayBetweenFrames() function.

Rating: 
Голосов пока нет

Delay after slave selection

When an SPI slave device needs additional time for initialization, you can configure delay after slave selection (SS). When enabled, the delay is introduces after SS line assertion and before transmission of the first data bit.

SPI Delay after slave selection

The default value of the delay after slave selection is 0ns. To adjust the delay value, use the DlnSpiMasterSetDelayAfterSS() function. To retrieve the current delay value, call the DlnSpiMasterGetDelayAfterSS() function.

Rating: 
Голосов пока нет

Delay between slave selections

Delay between slave selections is inserted after one SS line release and before assertion of another SS line.

SPI Delay between Slave Selections

The default value of the delay between slave selections is 62ns. The delay value is adjusted using the DlnSpiMasterSetDelayBetweenSS() function, and can be retrieved using the DlnSpiMasterGetDelayBetweenSS() function.

Rating: 
Голосов пока нет

SPI Master Transmission Functions

SPI master interface allows you a wide choice of functions for transmission data. These functions differ:

  • by operation mode;

  • by frame size;

  • by additional attributes.

The following list includes possible functions with brief descriptions:

DlnSpiMasterReadWrite()

Provides SPI communication in a full-duplex mode (sends and receives data). The function treats data as arrays of 8-bit frames.

DlnSpiMasterReadWrite16()

Provides SPI communication in a full-duplex mode (sends and receives data). The function treats data as arrays of frames up to 16 bits.

DlnSpiMasterReadWriteEx()

Provides SPI communication in a full-duplex mode (sends and receives data).The function treats data as arrays of 8-bit frames. When transmission completes, the function can release the SS line or leave it active.

DlnSpiMasterReadWriteSS()

Provides SPI communication in a full-duplex mode (sends and receives data). The function treats data as arrays of 8-bit frames. The function allows to select the specified SS line. When transmission completes, the function releases the SS line.

DlnSpiMasterRead()

Provides SPI communication in a half-duplex read mode (receives data). The function treats data as an array of 8-bit frames.

DlnSpiMasterReadEx()

Provides SPI communication in a half-duplex read mode (receives data). The function treats data as an array of 8-bit frames. When transmission completes, the function can release the SS line or leave it active.

DlnSpiMasterWrite()

Provides SPI communication in a half-duplex write mode (sends data). The function treats data as an array of 8-bit frames.

DlnSpiMasterWriteEx()

Provides SPI communication in a half-duplex write mode (sends data). The function treats data as an array of 8-bit frames. When transmission completes, the function can release the SS line or leave it active.

Rating: 
Голосов пока нет

Simple SPI Master Example

The following example shows how to transmit data over SPI bus. For brevity, this example uses default SPI configuration and does not include error detection. You can find the complete example in the “..\Program Files\Diolan\DLN\examples\c_cpp\examples\simple” folder after DLN setup package installation.

C/C++
#include "..\..\..\common\dln_generic.h"
#include "..\..\..\common\dln_spi_master.h"
#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

int _tmain(int argc, _TCHAR* argv[])
{
	// Open device
	HDLN device;
	DlnOpenUsbDevice(&device);

	// Set SPI frequency
	uint32_t frequency;
	DlnSpiMasterSetFrequency(device, 0, 100000, &frequency);

	// Enable SPI master
	uint16_t conflict;
	DlnSpiMasterEnable(device, 0, &conflict);

	// Prepare output buffer
	uint8_t input[10], output[10];
	for (int i = 0; i < 10; i++) output[i] = i;

	// Perform SPI transaction
	DlnSpiMasterReadWrite(device, 0, 10, output, input);

	// Print received data
	for (int i = 0; i < 10; i++) printf("%02x ", input[i]);

	// Disable SPI and close device
	DlnSpiMasterDisable(device, 0, 0);
	DlnCloseHandle(device);

	return 0;
}

  • Line 1:#include "..\..\..\common\dln_generic.h"

    The dln_generic..h header file declares functions and data structures for the generic interface.

  • Line 2: #include "..\..\..\common\dln_spi_master.h"

    The dln_spi_master.h header file declares functions and data structures for the SPI master interface.

  • Line 3:#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

    Use specified dln.lib library while project linking.

  • Line 9:DlnOpenUsbDevice(&device);

    The application establishes the connection with the DLN adapter. This application uses the USB connectivity of the adapter. For additional options, refer to the Device Opening & Identification section.

  • Line 13:DlnSpiMasterSetFrequency(device, 0, 100000, frequency);

    The application configures the frequency of the SPI master port 0. You can also configure SPI transmission mode, frame size, etc. See Configuring the SPI Master Interface for details.

  • Line 17:DlnSpiMasterEnable(device, 0, conflict);

    The application enables the SPI master port 0. The DlnSpiMasterEnable() function assigns the corresponding pins to the SPI master module and configures them. If some other module uses a pin required for the SPI bus interface, the DlnSpiMasterEnable() function returns the DLN_RES_PIN_IN_USE error code. The conflict parameter receives the pin’s number.

  • Lines 21:for (int i = 0; i < 10; i++) output[i] = i;

    The application allocates buffers for output and input data. The output buffer is filled with the sequential numbers from 0 to 9.

  • Line 24:DlnSpiMasterReadWrite(device, 0, 10, output, input);

    The DlnSpiMasterReadWrite() function transmits the data to and from the SPI slave device. See the SPI Master Transmission Functions section for additional data transmission functions.

  • Line 27:for (int i = 0; i < 10; i++) printf("%02x ", input[i]);

    The application prints the buffer received from the SPI slave device.

  • Line 30:DlnSpiMasterDisable(device, 0);

    The application releases the SPI master port.

  • Line 31:DlnCloseHandle(device);

    The application closes the handle to the DLN adapter.

Rating: 
Голосов пока нет

SPI Master Functions

The default configuration for the SPI master port is as 8-bit SPI master with CPOL=0 and CPHA=0 transmission parameters. By default, the clock is selected with a frequency of 1Mhz.

Using the SPI master functions allows you to change and check the current SPI master configuration, to control data transmission.

The SPI master functions include the following:

General port information:

DlnSpiMasterGetPortCount()

Retrieves the number of SPI master ports available in the DLN adapter.

DlnSpiMasterEnable()

Assigns the selected port to the SPI master module.

DlnSpiMasterDisable()

Releases the selected SPI master port.

DlnSpiMasterIsEnabled()

Retrieves whether the selected port is assigned to the SPI master module.

Configuration functions:

DlnSpiMasterSetFrequency()

Configures the clock frequency for the selected SPI master port.

DlnSpiMasterGetFrequency()

Retrieves the clock frequency configuration for the SPI master port.

DlnSpiMasterSetFrameSize()

Configures the size of a single data frame for the selected SPI master port.

DlnSpiMasterGetFrameSize()

Retrieves the data frame configuration for the selected SPI master port.

DlnSpiMasterSetMode()

Configures the transmission mode based on CPOL and CPHA values.

DlnSpiMasterGetMode()

Retrieves the transmission mode configuration for the selected SPI master port.

DlnSpiMasterSetCpol()

Configures the CPOL value for the selected SPI master port.

DlnSpiMasterGetCpol()

Retrieves the CPOL value for the selected SPI master port.

DlnSpiMasterSetCpha()

Configures the CPHA value for the selected SPI master port.

DlnSpiMasterGetCpha()

Retrieves the CPHA value for the selected SPI master port.

DlnSpiMasterGetSupportedModes()

Retrieves the supported transmission modes for the selected SPI master port.

DlnSpiMasterGetSupportedCpolValues()

Retrieves the supported CPOL values for the selected SPI master port.

DlnSpiMasterGetSupportedCphaValues()

Retrieves the supported CPHA values for the selected SPI master port.

Slave selection functions:

DlnSpiMasterGetSSCount()

Retrieves the available number of SS lines for the selected SPI master port.

DlnSpiMasterSetSS()

Selects a Slave Select (SS) line.

DlnSpiMasterGetSS()

Retrieves the selected SS line.

DlnSpiMasterSSEnable()

Activates the selected SS line.

DlnSpiMasterSSDisable()

Disables the selected SS line.

DlnSpiMasterSSIsEnabled()

Retrieves whether the selected SS line is activated.

DlnSpiMasterSSMultiEnable()

Activates several selected SS lines.

DlnSpiMasterSSMultiDisable()

Disables several selected SS lines.

DlnSpiMasterSSMultiIsEnabled()

Retrieves whether several selected SS lines are activated.

DlnSpiMasterReleaseSS()

Releases the selected SS line.

DlnSpiMasterSSBetweenFramesEnable()

Activates releasing SS line between data frames exchanged with a single slave device.

DlnSpiMasterSSBetweenFramesDisable()

Disables releasing SS line between data frames exchanged with a single slave device.

DlnSpiMasterSSBetweenFramesIsEnabled()

Retrieves whether releasing SS line between data frames is activated.

Transmission functions:

DlnSpiMasterReadWrite()

Provides SPI communication in a full-duplex mode with arrays of 8-bit frames.

DlnSpiMasterReadWrite16()

Provides SPI communication in a full-duplex mode with arrays of frames up to 16 bits.

DlnSpiMasterReadWriteEx()

Provides SPI communication in a full-duplex mode with arrays of 8-bit frames; can release the SS line after transmission.

DlnSpiMasterReadWriteSS()

Provides SPI communication in a full-duplex mode with arrays of 8-bit frames; releases the SS line after transmission.

DlnSpiMasterRead()

Provides SPI communication in a half-duplex read mode with arrays of 8-bit frames.

DlnSpiMasterReadEx()

Provides SPI communication in a half-duplex read mode with arrays of 8-bit frames; can release the SS line after transmission.

DlnSpiMasterWrite()

Provides SPI communication in a half-duplex write mode with arrays of 8-bit frames.

DlnSpiMasterWriteEx()

Provides SPI communication in a half-duplex write mode with arrays of 8-bit frames; can release the SS line after transmission.

Delay functions:

DlnSpiMasterSetDelayBetweenFrames()

Configures a delay between data frames exchanged with a single slave device.

DlnSpiMasterGetDelayBetweenFrames()

Retrieves current delay between data frames exchanged with a single slave device.

DlnSpiMasterSetDelayAfterSS()

Configures a delay between activating SS line and the first data frame.

DlnSpiMasterGetDelayAfterSS()

Retrieves current delay between activating SS line and the first data frame.

DlnSpiMasterSetDelayBetweenSS()

Configures a minimum delay between releasing one SS line and activating another SS line.

DlnSpiMasterGetDelayBetweenSS()

Retrieves current delay between releasing one SS line and activating another SS line.

The dln_spi_master.h file declares the SPI Master Interface functions.

Rating: 
Голосов пока нет

DlnSpiMasterGetPortCount() Function

The DlnSpiMasterGetPortCount() function retrieves the total number of SPI master ports available in your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetPortCount(
  HDLN handle,
  uint8_t* count
);
Parameters
handle

A handle to the DLN-series adapter.

count

A pointer to an unsigned 8-bit integer that receives the number of available SPI master ports.

Return Value
DLN_RES_SUCCESS (0x00)

The operation completed successfully and total number of SPI master ports were retrieved.

Remarks

The DlnSpiMasterGetPortCount() function is defined in the dln_spi_master.h file.

DlnSpiMasterEnable() Function

The DlnSpiMasterEnable() function activates the selected SPI master port on your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnSpiMasterEnable(
   HDLN handle,
   uint8_t port,
   uint16_t* conflict
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

conflict

A pointer to an unsigned 16-bit integer that receives the number of a conflicted pin, if any.

A conflict arises if the pin is already assigned to another module and cannot be used by the SPI module. To fix this, check which module uses the pin (call the DlnGetPinCfg()function), disconnect the pin from that module and call the DlnSpiMasterEnable() function once again. If there is another conflicting pin, its number will be returned.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the SPI master port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_PIN_IN_USE (0xA5)

The port cannot be activated as the SPI master port because one or more pins of the port are assigned to another module. The conflict parameter contains the number of a conflicting pin.

DLN_RES_NO_FREE_DMA_CHANNEL (0xAF)

The function cannot be executed because all DMA channels are assigned to another modules of the adapter.

Remarks

DLN-1 and DLN-2 adapters do not allow to change the SPI master configuration after the port is assigned to the SPI master module. Therefore, make sure you have configured the SPI master port before you enable it.

The DlnSpiMasterEnable() function is defined in the dln_spi_master.h file.

DlnSpiMasterDisable() Function

The DlnSpiMasterDisable() function releases the selected SPI master port on your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnSpiMasterDisable(
   HDLN handle,
   uint8_t port,
   uint8_t waitForTransferCompletion
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

waitForTransferCompletion

Used to choose whether the device should wait for current data transmissions to complete before disabling the SPI master. The following values are available:

  • 1 or DLN_SPI_MASTER_WAIT_FOR_TRANSFERS - wait until transmissions complete.

  • 0 or DLN_SPI_MASTER_CANCEL_TRANSFERS - cancel all pending data transmissions and release the port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the SPI master port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_TRANSFER_CANCELLED (0x20)

The pending transmissions were cancelled.

Remarks

The DlnSpiMasterDisable() function is defined in the dln_spi_master.h file.

DlnSpiMasterIsEnabled() Function

The DlnSpiMasterIsEnabled() function retrieves whether the specified SPI master port is activated.

Syntax
C/C++
DLN_RESULT DlnSpiMasterIsEnabled(
    HDLN handle,
    uint8_t port,
    uint8_t* enabled
 );
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

enabled

A pointer to an unsigned 8-bit integer that receives the information whether the specified SPI master port is activated. There are two possible values:

  • 0 or DLN_SPI_MASTER_DISABLED - the port is not configured as SPI master.

  • 1 or DLN_SPI_MASTER_ENABLED - the port is configured as SPI master.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved information about the SPI master port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterIsEnabled() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetFrequency() Function

The DlnSpiMasterSetFrequency() function sets the clock frequency on the SCK line, used to synchronize data transmission between master and slave devices.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetFrequency(
   HDLN handle,
   uint8_t port,
   uint32_t frequency,
   uint32_t* actualFrequency
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

frequency

SCK line frequency value, specified in Hz. You can specify any value within the range, supported by the DLN-series adapter. This range can be retrieved using the respective function. In case you enter an incompatible value, the function approximates it as the closest lower frequency value, supported by the adapter.

actualFrequency

A pointer to an unsigned 32-bit integer that receives the frequency approximated as the closest to user-defined lower value. The value is specified in Hz and can be null.

Frequency for DLN-4S and DLN-4M adapters is determined by 96 Mhz divided into 2.255. So the nearest frequency values will be 96/2 = 48 Mhz, 96/5 = 19,2 Mhz, 96/10 = 9,6 Mhz.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully set the clock frequency of the SCK line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

DLN_RES_VALUE_ROUNDED (0x21)

The frequency value has been approximated as the closest supported value.

Remarks

By default, the clock is selected with a frequency of 1Mhz. You can check the current value by using the DlnSpiMasterGetFrequency() function.

The DlnSpiMasterSetFrequency() function is defined in dln_spi_master.h file.

DlnSpiMasterGetFrequency() Function

The DlnSpiMasterGetFrequency() function retrieves the current setting for SPI clock frequency.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetFrequency(
   HDLN handle,
   uint8_t port,
   uint32_t* frequency
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

frequency

A pointer to an unsigned 32-bit integer that receives the current SPI clock frequency value in Hz.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the clock frequency.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetFrequency() function is defined in dln_spi_master.h file.

DlnSpiMasterSetFrameSize() Function

The DlnSpiMasterSetFrameSize() function sets the size of a single SPI data frame.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetFrameSize(
   HDLN handle,
   uint8_t port,
   uint8_t frameSize
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

frameSize

A number of bits to be transmitted. The DLN-series adapter supports 8 to 16 bits per frame.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the size of a SPI data frame.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_SPI_INVALID_FRAME_SIZE (0xB8)

The frame size is not valid. The DLN-series adapters support 8 to 16 bits per transmit.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

Remarks

The default frame size is set to 8 bits. To check the current frame size value, use the DlnSpiMasterGetFrameSize() function.

The DlnSpiMasterSetFrameSize() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetFrameSize() Function

The DlnSpiMasterGetFrameSize() function retrieves the current size setting for SPI data frame.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetFrameSize(
   HDLN handle,
   uint8_t port,
   uint8_t* frameSize
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

frameSize

A number of bits to be transmitted in a single frame. The DLN-series adapters support 8 to 16 bits per transmission.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the SPI data frame size.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetFrameSize() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetMode() Function

The DlnSpiMasterSetMode() function sets SPI transmission parameters (CPOL and CPHA).

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetMode(
    HDLN handle,
    uint8_t port,
    uint8_t mode
 );
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

mode

A bit field consisting of 8 bits. The bits 0 and 1 correspond to CPOL and CPHA parameters respectively and define the SPI mode. The rest of the bits are not used. You can also use the special constants, defined in the dln_spi_master.h file for each of the bits. See Clock Phase and Polarity for additional info.

BitValueDescriptionConstant

0

0

CPOL=0

DLN_SPI_MASTER_CPOL_0

0

1

CPOL=1

DLN_SPI_MASTER_CPOL_1

1

0

CPHA=0

DLN_SPI_MASTER_CPHA_0

1

1

CPHA=1

DLN_SPI_MASTER_CPHA_1

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the SPI transmission parameters.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

Remarks

By default, the DLN adapter’s SPI master port is configured to CPOL=0 CPHA=0 transmission mode.

The DlnSpiMasterSetMode() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetMode() Function

The DlnSpiMasterGetMode() function retrieves current configuration of the selected SPI master port.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetMode(
   HDLN handle,
   uint8_t port,
   uint8_t* mode
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

mode

A pointer to an unsigned 8 bit integer that receives the SPI mode description. See DlnSpiMasterSetMode() for details.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the SPI transmission parameters.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetMode() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetCpol() Function

The DlnSpiMasterSetCpol() function sets the clock polarity value.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetCpol(
    HDLN handle, 
    uint8_t port, 
    uint8_t cpol
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

cpol

Clock polarity value. Possible values: 0 or 1.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the SPI master CPOL value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

By default, SPI master ports of DLN adapters have CPOL=0 configuration.

The DlnSpiMasterSetCpol() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetCpol() Function

The DlnSpiMasterGetCpol() function retrieves the current value of clock polarity (CPOL).

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetCpol(
    HDLN handle, 
    uint8_t port, 
    uint8_t *cpol
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

cpol

The pointer to uint8_t variable which will be filled with current CPOL value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the SPI master CPOL value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetCpol() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetCpha() Function

The DlnSpiMasterSetCpha() function allows to set clock phase (CPHA) value.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetCpha(
    HDLN handle, 
    uint8_t port, 
    uint8_t cpha
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

cpha

The clock phase value. Can be 0 or 1.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the SPI master CPHA value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

By default, SPI master ports of DLN adapters have CPHA=0 configuration.

The DlnSpiMasterSetCpha() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetCpha() Function

The DlnSpiMasterGetCpha() function retrieves the current value of clock phase (CPHA).

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetCpha(
    HDLN handle, 
    uint8_t port, 
    uint8_t *cpha
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

cpha

The pointer to uint8_t variable which will be filled with current CPHA value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the SPI master CPHA value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetCpha() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetSupportedModes() Function

The DlnSpiMasterGetSupportedModes() function retrieves all supported SPI master modes (CPOL and CPHA values). For more information, read Clock Phase and Polarity.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetSupportedModes(
  HDLN handle, 
  uint8_t port, 
  DLN_SPI_MASTER_MODE_VALUES *values
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

values

Pointer to DLN_SPI_MASTER_MODE_VALUES type variable that receives available mode values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved supported transmission modes.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetSupportedModes() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetSupportedCpolValues() Function

The DlnSpiMasterGetSupportedCpolValues() function retrieves supported CPOL values.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetSupportedCpolValues(
  HDLN handle, 
  uint8_t port, 
  DLN_SPI_MASTER_CPOL_VALUES *values
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

values

Pointer to DLN_SPI_MASTER_CPOL_VALUES type variable that receives available CPOL values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved supported CPOL values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetSupportedCpolValues() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetSupportedCphaValues() Function

The DlnSpiMasterGetSupportedCphaValues() function retrieves the available CPHA values.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetSupportedCphaValues(
  HDLN handle, 
  uint8_t port, 
  DLN_SPI_MASTER_CPHA_VALUES *values
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

values

Pointer to DLN_SPI_MASTER_CPHA_VALUES type variable that receives the supported CPHA values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved supported CPHA values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetSupportedCphaValues() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetSSCount() Function

The DlnSpiMasterGetSSCount() function returns the available number of SS lines.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetSSCount(
    HDLN handle, 
    uint8_t port, 
    uint16_t *count
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

count

The pointer to uint16_t type variable that receives the number of available SS lines.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetSSCount() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetSS() Function

The DlnSpiMasterSetSS() function selects a Slave Select (SS) line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetSS(
   HDLN handle,
   uint8_t port,
   uint8_t ss
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port to be configured.

ss

The value on the SS lines. The bits 4-7 are reserved and must be set to 1.

If you expect slaves to output data, you must ensure that only one slave is activated. If several slaves start outputting data simultaneously, the equipment can be damaged.
Return Value
DLN_RES_SUCCESS (0x00)

The function successfully selected the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

DLN_RES_SPI_MASTER_INVALID_SS_NUMBER (0xB9)

The SS value is not valid.

Remarks

The DlnSpiMasterSetSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetSS() Function

The DlnSpiMasterGetSS() function retrieves current Slave Select (SS) line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetSS(
   HDLN handle,
   uint8_t port,
   uint8_t* ss
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ss

A pointer to an unsigned 8-bit integer that receives the value on the SS lines.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current value on the SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterGetSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSEnable() Function

The DlnSpiMasterSSEnable() function enables the specified SS line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSEnable(
    HDLN handle, 
    uint8_t port, 
    uint8_t ss
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ss

The number of the SS line.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully enabled the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_SPI_MASTER_INVALID_SS_VALUE (0xB9)

The number of the SS line is invalid. Use the DlnSpiMasterGetSSCount() function to check the available number of SS lines.

Remarks

The DlnSpiMasterSSEnable() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSDisable() Function

The DlnSpiMasterSSDisable() function disables the specified SS line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSDisable(
    HDLN handle, 
    uint8_t port, 
    uint8_t ss
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ss

The number of the SS line.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disabled the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_SPI_MASTER_INVALID_SS_VALUE (0xB9)

The number of the SS line is invalid. Use the DlnSpiMasterGetSSCount() function to check the available number of SS lines.

Remarks

The DlnSpiMasterSSDisable() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSIsEnabled() Function

The DlnSpiMasterSSIsEnabled() function enables the specified SS line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSEnable(
    HDLN handle, 
    uint8_t port,
    uint8_t ss, 
    uint8_t *enabled
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ss

The number of the SS line.

enabled

A pointer to an unsigned 8-bit integer that receives the information whether the specified SS line is enabled.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disabled the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_SPI_MASTER_INVALID_SS_VALUE (0xB9)

The number of the SS line is invalid. Use the DlnSpiMasterGetSSCount() function to check the available number of SS lines.

Remarks

The DlnSpiMasterSSIsEnabled() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSMultiEnable() Function

The DlnSpiMasterSSMultiEnable() function enables the specified SS lines.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSMultiEnable(
    HDLN handle, 
    uint8_t port, 
    uint8_t ssMask
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ssMask

A pointer to an unsigned 8-bit integer that receives status of SS lines.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved status of SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterSSMultiEnable() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSMultiDisable() Function

The DlnSpiMasterSSMultiDisable() function enables the specified SS lines.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSEnable(
    HDLN handle, 
    uint8_t port, 
    uint8_t ssMask
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

ssMask

The field that defines what SS lines of the port should be disabled. To disable the SS line, set 0 to the corresponding bit.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disabled the SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterSSMultiDisable() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSMultiIsEnabled() Function

The DlnSpiMasterSSMultiIsEnabled() function enables the specified SS lines.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSMultiIsEnabled(
    HDLN handle, 
    uint8_t port, 
    uint8_t *enabled
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

enabled

A pointer to an unsigned 8-bit integer that receives the information about status of SS lines. There are two possible values for every bit:

  • 0 - the SS line is disabled.

  • 1 - the SS line is enabled.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved status of the SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterSSMultiEnable() function is defined in the dln_spi_master.h file.

DlnSpiMasterReleaseSS() Function

The DlnSpiMasterReleaseSS() function releases SS lines.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReleaseSS(
    HDLN handle, 
    uint8_t port
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully released SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiMasterReleaseSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterSSBetweenFramesEnable() Function

The DlnSpiMasterSSBetweenFramesEnable() function enables release of an SS line between data frames exchanged with a single slave device.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSBetweenFramesEnable(
   HDLN handle,
   uint8_t port
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully enabled release of the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

Remarks
DLN-1 and DLN-2 adapters do not support releasing the slave select line between frames.

The DlnSpiMasterSSBetweenFramesEnable() function is defined in dln_spi_master.h file.

DlnSpiMasterSSBetweenFramesDisable() Function

The DlnSpiMasterSSBetweenFramesDisable() function disables release of an SS line between data frames exchanged with a single slave device.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSBetweenFramesDisable(
   HDLN handle,
   uint8_t port
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disabled release of the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

Remarks
DLN-1 and DLN-2 adapters do not support releasing the slave select line between frames.

The DlnSpiMasterSSBetweenFramesDisable() function is defined in dln_spi_master.h file.

DlnSpiMasterSSBetweenFramesIsEnabled() Function

The DlnSpiMasterSSBetweenFramesIsEnabled() function checks whether the DLN-series adapter releases SS line between successive SPI frames transmission.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSSBetweenFramesIsEnabled(
   HDLN handle,
   uint8_t port,
   uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

enabled

A pointer to an unsigned 8-bit integer that receives information whether release of an SS line is enabled. The following values are available:

  • 1 or DLN_SPI_MASTER_SS_BETWEEN_TRANSFERS_ENABLED - the SS line release is enabled.

  • 0 or DLN_SPI_MASTER_SS_BETWEEN_TRANSFERS_DISABLED - the SS line release is disabled.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieves information about the release of the SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks
DLN-1 and DLN-2 adapters do not support releasing the slave select line between frames.

The DlnSpiMasterSSBetweenFramesIsEnabled() function is defined in dln_spi_master.h file.

DlnSpiMasterReadWrite() Function

The DlnSpiMasterReadWrite() function sends and receives data via SPI bus. The received and sent data are arrays of 1-byte elements. This function is suited to transmit data frames of 8 bits or less. In case you set a frame size more than 8 bits, it is advised to use the DlnSpiMasterReadWrite16() function.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReadWrite(
    HDLN handle, 
    uint8_t port, 
    uint16_t size, 
    uint8_t *writeBuffer, 
    uint8_t *readBuffer
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

writeBuffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to a slave during the function execution.

readBuffer

A pointer to an array of unsigned 8-bit integers that receives data from the slave during the function execution.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully transmitted data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterReadWrite() function is defined in dln_spi_master.h file.

DlnSpiMasterReadWrite16() Function

The DlnSpiMasterReadWrite16() function sends and receives 2-byte frames via SPI bus.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReadWrite16(
   HDLN handle,
   uint8_t port,
   uint16_t count,
   uint16_t* writeBuffer,
   uint16_t* readBuffer
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

count

The number of 2-byte array elements.

writeBuffer

A pointer to an array of unsigned 16-bit integer that receives data to be sent to the slave during the function execution.

readBuffer

A pointer to an array unsigned 16-bit integer that receives data from the slave during the function execution.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully transmitted data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterReadWrite16() function transmits data frames of 9 to 16 bits. To specify the size of data frames, use the DlnSpiMasterSetFrameSize() function. In DLN adapters, the frame data is transmitted in a Little Endian format. If the frame size is not a multiple of 8, the most-significant bits are discarded. For details, read SPI Data Frames.

The DlnSpiMasterReadWrite16() function is defined in the dln_spi_master.h file.

DlnSpiMasterReadWriteSS() Function

The DlnSpiMasterReadWriteSS() function selects the specified SS line, transmits data via SPI bus and releases the SS line.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReadWriteSS(
    HDLN handle, 
    uint8_t port,
C/C++
    uint8_t ss, 
    uint16_t size, 
    uint8_t *writeBuffer, 
    uint8_t *readBuffer
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the selected SPI master port.

ss

The value on the SS lines. This value can include only one zero bit.

size

The size of the message buffer. This parameter is specified in bytes.

writeBuffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to a slave.

readBuffer

A pointer to an array of unsigned 8-bit integers that receives data from the slave.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully transmitted data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterReadWriteSS() function is defined in dln_spi_master.h file.

DlnSpiMasterReadWriteEx() Function

The DlnSpiMasterReadWriteEx() function sends and receives data via SPI bus. The data is transmitted as an array of 1-byte elements. In this function you can use additional attributes to configure the SS line state after data transmission.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReadWriteEx(
  HDLN handle, 
  uint8_t port, 
  uint16_t size, 
  uint8_t *writeBuffer, 
  uint8_t *readBuffer, 
  uint8_t attribute
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

writeBuffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to a slave during the function execution.

readBuffer

A pointer to an array of unsigned 8-bit integers that receives data from slave during the function execution.

attribute

Additional transmission attribute:

  • DLN_SPI_MASTER_ATTR_LEAVE_SS_LOW - Leave SS low after transmission.

  • DLN_SPI_MASTER_ATTR_RELEASE_SS - Release SS after transmission.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully transmitted data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterReadWriteEx() function is defined in the dln_spi_master.h file.

DlnSpiMasterRead() Function

The DlnSpiMasterRead() function receives data via SPI bus. The received data is an array of 1-byte elements.

Syntax
C/C++
DLN_RESULT DlnSpiMasterRead(
  HDLN handle, 
  uint8_t port, 
  uint16_t size, 
  uint8_t *readBuffer
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

readBuffer

A pointer to an array of unsigned 8-bit integers that receives data from slave during the function execution.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully received data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterRead() function is defined in the dln_spi_master.h file.

DlnSpiMasterReadEx() Function

The DlnSpiMasterReadEx() function receives data via SPI bus. The received data is an array of 1-byte elements. In this function you can use additional attributes to configure the SS line state after data transmission.

Syntax
C/C++
DLN_RESULT DlnSpiMasterReadEx(
  HDLN handle, 
  uint8_t port, 
  uint16_t size, 
  uint8_t *readBuffer, 
  uint8_t attribute
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

readBuffer

A pointer to an array of unsigned 8-bit integers that receives data from slave during the function execution.

attribute

Additional transmission attribute.

  • DLN_SPI_MASTER_ATTR_LEAVE_SS_LOW - Leave SS low after transmission.

  • DLN_SPI_MASTER_ATTR_RELEASE_SS - Release SS after transmission.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully received data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterReadEx() function is defined in the dln_spi_master.h file.

DlnSpiMasterWrite() Function

The DlnSpiMasterWrite() function sends data via SPI bus. The data is sent as an array of 1-byte elements.

Syntax
C/C++
DLN_RESULT DlnSpiMasterWrite(
  HDLN handle, 
  uint8_t port, 
  uint16_t size, 
  uint8_t *writeBuffer
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

writeBuffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to a slave.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully sent data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterWriteEx() function is defined in the dln_spi_master.h file.

DlnSpiMasterWriteEx() Function

The DlnSpiMasterWriteEx() function sends data via SPI bus. The data is sent as an array of 1-byte elements. By using this function you can use additional attributes.

Syntax
C/C++
DLN_RESULT DlnSpiMasterWriteEx(
  HDLN handle, 
  uint8_t port, 
  uint16_t size, 
  uint8_t *writeBuffer, 
  uint8_t attribute
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

size

The size of the message buffer. This parameter is specified in bytes. The maximum value is 256 bytes.

writeBuffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to a slave.

attribute

Additional transmission attribute.

  • DLN_SPI_MASTER_ATTR_LEAVE_SS_LOW - Leave SS low after transmission.

  • DLN_SPI_MASTER_ATTR_RELEASE_SS - Release SS after transmission.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully sent data.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_DISABLED (0xB7)

The SPI master port is disabled. Use the DlnSpiMasterEnable() function to activate the SPI master port.

Remarks

The DlnSpiMasterWriteEx() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetDelayBetweenFrames() Function

The DlnSpiMasterSetDelayBetweenFrames() function sets a delay between data frames exchanged with a single slave device. For more information, read SPI Delays.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetDelayBetweenFrames(
   HDLN handle,
   uint8_t port,
   uint32_t delayBetweenFrames,
   uint32_t* actualDelayBetweenFrames
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port to be configured.

delayBetweenFrames

The delay value in nanoseconds. If you specify an unsupported value, it will be approximated as the closest higher supported value.

actualDelayBetweenFrames

Actual set delay value in nanoseconds.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully set the delay between data frames.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

DLN_RES_VALUE_ROUNDED (0x21)

The delay value has been approximated as the closest supported value.

Remarks
DLN-1 and DLN-2 adapters do not support delays between frames.

The DlnSpiMasterSetDelayBetweenFrames() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetDelayBetweenFrames() Function

The DlnSpiMasterGetDelayBetweenFrames() function retrieves current setting for delay between data frames exchanged with a single slave device.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetDelayBetweenFrames(
   HDLN handle,
   uint8_t port,
   uint32_t* delayBetweenFrames
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

delayBetweenFrames

A pointer to an unsigned 32-bit integer that receives the current delay value in nanoseconds.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the delay between data frames.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks
DLN-1 and DLN-2 adapters do not support delays between frames.

The DlnSpiMasterGetDelayBetweenFrames() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetDelayAfterSS() Function

The DlnSpiMasterSetDelayAfterSS() function sets a delay duration between assertion of an SS line and first data frame. For more information, read SPI Delays.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetDelayAfterSS(
   HDLN handle,
   uint8_t port,
   uint32_t delayAfterSS,
   uint32_t* actualDelayAfterSS
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

delayAfterSS

The delay value in nanoseconds. If you specify an unsupported value, it will be approximated as the closest higher supported value.

If you set a 0ns delay time, the actual delay will be equal to 1/2 of the SPI clock frequency, specified by the DlnSpiMasterSetFrequency() function.
Return Value
DLN_RES_SUCCESS (0x00)

The function successfully set the delay after slave selection.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

DLN_RES_VALUE_ROUNDED (0x21)

The delay value has been approximated as the closest supported value.

Remarks
DLN-1 and DLN-2 adapters do not support delays after slave selection.

The DlnSpiMasterSetDelayAfterSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetDelayAfterSS() Function

The DlnSpiMasterGetDelayAfterSS() function retrieves the current setting for minimum delay between assertion of an SS line and the first data frame.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetDelayAfterSS(
   HDLN handle,
   uint8_t port,
   uint32_t* delayAfterSS
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

delayAfterSS

A pointer to an unsigned 32-bit integer that receives the current delay value in nanoseconds.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the delay after slave selection.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks
DLN-1 and DLN-2 adapters do not support delays after slave selection.

The DlnSpiMasterGetDelayAfterSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterSetDelayBetweenSS() Function

The DlnSpiMasterSetDelayBetweenSS() function sets a minimum delay between release of an SS line and assertion of another SS line. For more information, read SPI Delays.

Syntax
C/C++
DLN_RESULT DlnSpiMasterSetDelayBetweenSS(
   HDLN handle,
   uint8_t port,
   uint32_t delayBetweenSS,
   uint32_t* actualDelayBetweenSS
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

delayBetweenSS

The delay value in nanoseconds. If you specify an unsupported value, it will be approximated as the closest higher supported value.

actualDelayBetweenSS

Actual set delay value in nanoseconds.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully set the delay after one SS line is released and before another SS line is asserted.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

DLN_RES_BUSY (0xB6)

The SPI master is busy transmitting.

DLN_RES_VALUE_ROUNDED (0x21)

The delay value has been approximated as the closest supported value.

Remarks
DLN-1 and DLN-2 adapters do not support delays between slave selections.

The DlnSpiMasterSetDelayBetweenSS() function is defined in the dln_spi_master.h file.

DlnSpiMasterGetDelayBetweenSS() Function

The DlnSpiMasterGetDelayBetweenSS() function retrieves the current setting for minimum delay after one SS line is released and before another SS line is asserted.

Syntax
C/C++
DLN_RESULT DlnSpiMasterGetDelayBetweenSS(
   HDLN handle,
   uint8_t port,
   uint32_t* delayBetweenSS
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI master port.

delayBetweenSS

A pointer to an unsigned 32-bit integer that receives the current delay value in nanoseconds.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully set the delay after one SS line is released and before another SS line is asserted.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiMasterGetPortCount() function to find the maximum possible port number.

Remarks
DLN-1 and DLN-2 adapters do not support delays between slave selections.

The DlnSpiMasterGetDelayBetweenSS() function is defined in the dln_spi_master.h file.