SPI Bus Interface

The Serial Peripheral Interface (SPI) bus is a synchronous serial communication interface used for short distance communication between various peripheral devices. The SPI bus interconnects a single master device with one or more slave devices.

The master device originates the data transmission by selecting a slave device and generating a clock. Data is transmitted in both directions simultaneously (full-duplex mode) or in one direction (half-duplex mode).

DLN adapters can operate as a master device (read SPI Master Interface). DLN-4S adapter can also operate as a slave device (read SPI Slave Interface).

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

SPI Bus Structure

The SPI bus uses four signal lines:

  • SCK (Clock) – The master generates the clock to synchronize data transmission.

  • MOSI (Master Output, Slave Input) – The master sends data on the MOSI line, the slave receives it.

  • MISO (Master Input, Slave Output) – The slave sends data on the MISO line, the master receives it.

  • CS or SS (Chip Select or Slave Select) – The master drops the SS line to select the specific SPI slave device. The DLN adapters have several SS lines that you can connect to different slave devices.

Among these four lines, two of them (MOSI and MISO) are data lines, the other two (SS and SCK) are control and synchronization lines.

The SPI bus with a single master and a single slave connects the devices in the following way:

SPI Single Slave

The SPI bus with a single master and multiple slaves connects the devices in the following way:

SPI Multi Slave

There are different ways to connect multiple slaves to a single master. See Connecting Multiple Slave Devices for additional information.

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

SPI Communication

To initiate communication, the SPI master selects the slave (by pulling the corresponding SS line low) and starts generating the clock signal.

The clock signal synchronizes data transmission both from the master to a slave (the MOSI line) and from the slave to the master (the MISO line). The clock phase and polarity defines the clock phases where the master and the slave can sample data on the MOSI and MISO lines.

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

SPI Flash Interface

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

SPI Flash Functions

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

DlnSpiFlashGetPortCount() Function

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

Syntax
C/C++
DLN_RESULT DlnSpiFlashGetPortCount(
  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 flash ports.

Return Value
DLN_RES_SUCCESS (0x00)

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

Remarks

The DlnSpiFlashGetPortCount() function is defined in the dln_spi_flash.h file.

DlnSpiFlashEnable() Function

The DlnSpiFlashEnable() function activates the specified SPI flash port on your DLN-series adapter.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

conflict

A pointer to an unsigned 16-bit integer that receives a number of the conflicted pin, if any.A conflict arises if a pin is already assigned to another module of the DLN-series adapter and cannot be used by the SPI flash 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 flash port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashEnable() function is defined in the dln_spi_flash.h file.

DlnSpiFlashDisable() Function

The DlnSpiFlashDisable() function deactivates the specified SPI flash port on your DLN-series adapter.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the SPI flash port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashDisable() function is defined in the dln_spi_flash.h file.

DlnSpiFlashIsEnabled() Function

The DlnSpiFlashIsEnabled() function retrieves information whether the specified SPI flash port is activated.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

enabled

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

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

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

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the SPI flash port status.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashIsEnabled() function is defined in the dln_spi_flash.h file.

DlnSpiFlashSetFrequency() Function

The DlnSpiFlashSetFrequency() function sets the clock frequency on the SCK line.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

frequency

SCK line frequency value, specified in Hz. You can specify any value within the range, supported by the DLN-series adapter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the clock frequency.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashSetFrequency() function is defined in dln_spi_flash.h file.

DlnSpiFlashGetFrequency() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI flash 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 current clock frequency.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashGetFrequency() function is defined in the dln_spi_flash.h file.

DlnSpiFlashSetSS() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

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 DlnSpiFlashGetPortCount() function to find the maximum possible port number.

Remarks

The DlnSpiFlashSetSS() function is defined in dln_spi_flash.h file.

DlnSpiFlashGetSS() Function

The DlnSpiFlashGetSS() function retrieves the current Slave Select (SS) line.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash 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 retrieves the selected SS line.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashGetSS() function is defined in dln_spi_flash.h file.

DlnSpiFlashSetSSMask() Function

The DlnSpiFlashSetSSMask() function selects a required Slave Select (SS) lines by using mask value.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

ssMask

The mask value to set 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 SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashSetSSMask() function is defined in dln_spi_flash.h file.

DlnSpiFlashGetSSMask() Function

The DlnSpiFlashGetSSMask() function retrieves the mask value of current selected Slave Select (SS) lines.

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

A handle to the DLN-series adapter.

port

A number of the SPI flash port to retrieve the information from.

ssMask

A pointer to an unsigned 8-bit integer that receives the mask value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the selected SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiFlashGetSSMask() function is defined in the dln_spi_flash.h file.

DlnSpiFlashProgramPage() Function

The DlnSpiFlashProgramPage() function transfers data by using SPI flash interface.

Syntax
C/C++
DLN_RESULT DlnSpiFlashProgramPage(
  HDLN handle, 
  uint8_t port, 
  uint32_t address, 
  uint8_t *buffer, 
  uint16_t size, 
  uint32_t timeout
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

address

Address value.

buffer

Pointer to byte variable with data to be sent.

size

Buffer size.

timeout

Timeout value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the selected SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The buffer size is not valid. This value cannot exceed 256 bytes.

DLN_RES_DISABLED (0xB7)

The SPI flash port is disabled. Use the DlnSpiFlashEnable() function to activate the SPI flash port.

Remarks

The DlnSpiFlashProgramPage() function is defined in dln_spi_flash.h file.

DlnSpiFlashReadPage() Function

The DlnSpiFlashReadPage() function receives data via SPI flash interface. The data is received as an array of 1-byte elements.

Syntax
C/C++
DLN_RESULT DlnSpiFlashReadPage(
  HDLN handle, 
  uint8_t port, 
  uint32_t address, 
  uint8_t *buffer, 
  uint16_t size
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI flash port.

address

Device address for reading data from.

buffer

A pointer to an array of unsigned 8-bit integers. This array will be filled with data received.

size

Read data size.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the selected SS lines.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The buffer size is not valid. This value cannot exceed 256 bytes.

DLN_RES_DISABLED (0xB7)

The SPI flash port is disabled. Use the DlnSpiFlashEnable() function to activate the SPI flash port.

Remarks

The DlnSpiFlashReadPage() function is defined in the dln_spi_flash.h file.

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.

SPI Slave Interface

Some DLN-series adapters support the SPI Slave Interface.

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

Configuring the Slave for Communication

To configure the slave for the communication, follow these steps:

  1. Configure SS idle timeout. When you enable the SPI slave, the SS line may be busy. The DLN adapter waits until the SS line drives high. If the SS line is not released during the SS idle timeout, the SPI slave cannot be enabled. Read SS Idle Timeout.

  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.

  3. Configure loading data to the reply buffer. The reply mode and reply type parameters can prevent from losing data if the frame size, configured by you for the SPI slave, does not correspond the frame size set on the SPI master. Read SPI Slave Reply Buffer.

  4. If needed, configure events. DLN adapters provide event-driven interface for SPI slave devices. Read SPI Slave Events.

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

SS Idle Timeout

When you try to enable the SPI slave module, the SS line can appear busy. To prevent transmitting incorrect data, the DLN adapter idles until the SS line is released (drives high). Only then, the SPI slave can be enabled.

To limit the idle time, you can specify the idle timeout value in milliseconds (ms) by calling the DlnSpiSlaveSetSSIdleTimeout() function. The default value is 100ms. The idle timeout can be from 1ms to 1000ms. If during the specified idle timeout the SS line was not released, the DlnSpiSlaveEnable() function returns the DLN_RES_SPI_SLAVE_SS_IDLE_TIMEOUT error.

Do not mix SS idle timeout and idle event timeout.

For details about idle event timeout, read DLN_SPI_SLAVE_EVENT_IDLE Events.

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

SPI Slave Reply Buffer

When the master initiates transmission, the DLN adapter-slave fills the reply buffer with data that should be sent to the master. To fill the reply buffer, you can use the following functions: DlnSpiSlaveLoadReply() or DlnSpiSlaveEnqueueReply(). The DlnSpiSlaveLoadReply() function clears the buffer and makes the current reply the first in the queue. In contrast, the DlnSpiSlaveEnqueueReply() function puts the current reply to the end of the queue.

Transmitted data is limited to the number of frames received by the master. The sizes of slave buffer (reply buffer) and master buffer (received buffer) may differ.

If the reply buffer size exceeds the received buffer size, the last bytes of the reply buffer can be lost or sent with the following transmission. It depends on the reply mode you configure. For more information, read Reply Modes.

If the reply buffer size is less than the received buffer size, the last bytes can be filled by zeroes or by repeated reply bytes. It depends on the shortage action you configure. For details, read Reply Shortage Actions.

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

Reply Modes

If the reply buffer size exceeds the size of the buffer received by the master, the following options are possible:

  • If the last bytes of the reply are not weighty, they can be rejected. In this case, the master receives the bytes from the reply buffer until the SS line rises. The last bytes of the reply buffer are lost. This mode is called DLN_SPI_SLAVE_REPLY_MODE_SS_BASED.

  • If you do not want to lose any data, the last buffers can be added to the queue. In this case, the master receives the bytes from the reply buffer until the SS line rises. The last bytes of the reply buffer are not lost, they are added to the queue and the master receives them with the next transmission. This mode is called DLN_SPI_SLAVE_REPLY_MODE_COUNT_BASED.

You have two loaded replies: ABCD and EF12. The master initiates two transmissions of 3 words in each. From the slave, the master receives the following:

  • In the DLN_SPI_SLAVE_REPLY_MODE_SS_BASED mode, the master receives ABC and EF1. The last bytes of every reply are lost.

    DLN_SPI_SLAVE_REPLY_MODE_SS_BASED mode

  • In the DLN_SPI_SLAVE_REPLY_MODE_COUNT_BASED mode, the master receives ABC and DEF. The last bytes of the second reply is queued for the following transmissions.

    DLN_SPI_SLAVE_REPLY_MODE_COUNT_BASED

To configure the reply mode, use the DlnSpiSlaveSetReplyMode() function. The DlnSpiSlaveGetSupportedReplyModes() function retrieves all supported reply modes.

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

Reply Shortage Actions

If the reply buffer size is less than the size of the buffer received by the master, the missed bytes can be filled by zeroes (the DLN_SPI_SLAVE_REPLY_SHORTAGE_SEND_ZEROES reply type) or by repeating the reply bytes (the DLN_SPI_SLAVE_REPLY_SHORTAGE_REUSE reply type).

You have a loaded reply: ABCD. The master initiates a transmission of 6 words. From the slave, the master receives the following:

  • If the DLN_SPI_SLAVE_REPLY_SHORTAGE_SEND_ZEROES reply type is set, the master receives ABCD00. The last bytes are filled with zeroes.

    DLN_SPI_SLAVE_REPLY_SHORTAGE_SEND_ZEROES reply type

  • If the DLN_SPI_SLAVE_REPLY_SHORTAGE_REUSE reply type is set, the master receives ABCDAB. The last bytes are filled by repeating the first bytes of the reply.

    DLN_SPI_SLAVE_REPLY_SHORTAGE_REUSE reply type

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

SPI Slave Events

DLN adapters-slaves can be configured to send events. The events are generated when the slave meets the certain predefined conditions.

DLN adapters-slaves support the following events:

Event TypeDescription

DLN_SPI_SLAVE_EVENT_NONE

A DLN adapter does not generate any events.

DLN_SPI_SLAVE_EVENT_SS_RISE

A DLN adapter generates events when the level on the SS line rises. For details, read DLN_SPI_SLAVE_EVENT_SS_RISE Events.

DLN_SPI_SLAVE_EVENT_BUFFER_FULL

A DLN adapter generates events when the buffer is full. For details, read DLN_SPI_SLAVE_EVENT_BUFFER_FULL Events.

DLN_SPI_SLAVE_EVENT_IDLE

A DLN adapter generates events when the slave idles for the configured time. For details, read DLN_SPI_SLAVE_EVENT_IDLE Events.

When an event occurs, your application is notified (see the Notifications section). Call the DlnGetMessage() function to obtain the event details. The DLN_SPI_SLAVE_DATA_RECEIVED_EV structure describes this information.

By default, event generation is disabled (DLN_SPI_SLAVE_EVENT_NONE).

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

DLN_SPI_SLAVE_EVENT_SS_RISE Events

A DLN adapter generates the DLN_SPI_SLAVE_EVENT_SS_RISE events each time the level on the SS line rises.

DLN_SPI_SLAVE_EVENT_SS_RISE event

When the transmission from/to the SPI master completes, the master rises the level on the SS line. At this moment, a DLN adapter-slave generates the DLN_SPI_SLAVE_EVENT_SS_RISE event. After receiving this event, your application can perform certain actions, for example, show received data or start processing them.

The eventCount field of the first event is set to zero. For every new DLN_SPI_SLAVE_EVENT_SS_RISE event, the eventCount field increments. When you reset the slave or change its configuration, the eventCount filed is reset to zero.

Use the DlnSpiSlaveEnableSSRiseEvent() function to enable generating these events. To disable this event, use the DlnSpiSlaveDisableSSRiseEvent() function. The DlnSpiSlaveIsSSRiseEventEnabled() function allows to check whether this event is enabled.

The DLN_SPI_SLAVE_EVENT_SS_RISE and DLN_SPI_SLAVE_EVENT_IDLE events are conflicting; therefore when you enable one of these events, check that the other one is disabled.
Rating: 
Голосов пока нет

DLN_SPI_SLAVE_EVENT_BUFFER_FULL Events

A DLN adapter generates the DLN_SPI_SLAVE_EVENT_BUFFER_FULL events each time the buffer becomes full.

DLN_SPI_SLAVE_EVENT_BUFFER_FULL event

You can configure the buffer size by calling the DlnSpiSlaveSetEventSize() function. The supported values are from 1 to 256 bytes. By default, the size parameter is set to 256 bytes. To check the current value, use the DlnSpiSlaveGetEventSize() function.

During the transmission from the SPI master, if the buffer is overfilled, a DLN adapter-slave generates the DLN_SPI_SLAVE_EVENT_BUFFER_FULL event.

The eventCount field of the first event is set to zero. For every new DLN_SPI_SLAVE_EVENT_SS_RISE event, the eventCount field increments. When you reset the slave or change its configuration, the eventCount filed is reset to zero.

Use the DlnSpiSlaveEnableEvent() function to enable generating these events. To disable this event, use the DlnSpiSlaveDisableEvent() function. The DlnSpiSlaveIsEventEnabled() function allows to check whether this event is enabled.

The DLN_SPI_SLAVE_EVENT_BUFFER_FULL event does not conflict with other events.

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

DLN_SPI_SLAVE_EVENT_IDLE Events

A DLN adapter generates the DLN_SPI_SLAVE_EVENT_IDLE events each time the SS line stays raised for a certain time.

DLN_SPI_SLAVE_EVENT_IDLE event

When the transmission from/to the SPI master completes, the master rises the level on the SS line. If the level stays high for the time set in the timeout parameter, a DLN adapter-slave generates the DLN_SPI_SLAVE_EVENT_IDLE event. If the SS line stays in the high level less than the required idle timeout, the event does not occur.

To configure the timeout parameter, use the DlnSpiSlaveSetIdleEventTimeout() function. The DlnSpiSlaveSetIdleEventTimeout() function allows to check the current value of this parameter.

Use the DlnSpiSlaveEnableIdleEvent() function to enable generating DLN_SPI_SLAVE_EVENT_IDLE events. To disable this event, use the DlnSpiSlaveDisableIdleEvent() function. The DlnSpiSlaveIsIdleEventEnabled() function allows to check whether this event is enabled.

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

SPI Slave Functions

The default configuration for the SPI slave port is as 8-bit SPI slave with CPOL=0 and CPHA=0 transmission parameters. By default, no events are generated.

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

The SPI slave functions include the following:

General port information:

DlnSpiSlaveGetPortCount()

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

DlnSpiSlaveEnable()

Assigns the selected port to the SPI slave module.

DlnSpiSlaveDisable()

Releases the selected SPI slave port.

DlnSpiSlaveIsEnabled()

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

Configuration functions:

DlnSpiSlaveSetSSIdleTimeout()

Specifies idle timeout for releasing the SS line.

DlnSpiSlaveGetSSIdleTimeout()

Retrieves the idle timeout setting.

DlnSpiSlaveSetFrameSize()

Specifies the data frame size for the selected SPI slave port.

DlnSpiSlaveGetFrameSize()

Retrieves the current frame size for the selected SPI slave port.

DlnSpiSlaveGetSupportedFrameSizes()

Retrieves the supported frame sizes.

DlnSpiSlaveSetMode()

Specifies transmission parameters (CPOL and CPHA) for the selected SPI slave port.

DlnSpiSlaveGetMode()

Retrieves the current transmission parameters (CPOL and CPHA) for the selected SPI slave port.

DlnSpiSlaveGetSupportedModes()

Retrieves the supported transmission parameters (CPOL and CPHA).

DlnSpiSlaveSetCpha()

Specifies CPHA value for the selected SPI slave port.

DlnSpiSlaveGetCpha()

Retrieves the current CPHA value for the selected SPI slave port.

DlnSpiSlaveGetSupportedCphaValues()

Retrieves the supported CPHA values.

DlnSpiSlaveSetCpol()

Specifies CPOL value for the selected SPI slave port.

DlnSpiSlaveGetCpol()

Retrieves the current CPOL value for the selected SPI slave port.

DlnSpiSlaveGetSupportedCpolValues()

Retrieves the supported CPOL values.

Reply functions:

DlnSpiSlaveLoadReply()

Clears the buffer and makes the current reply the first in the queue.

DlnSpiSlaveEnqueueReply()

Puts the current reply to the end of the queue.

DlnSpiSlaveSetReplyMode()

Specifies actions if the reply buffer size exceeds the size of the buffer received by the master.

DlnSpiSlaveGetReplyMode()

Retrieves the current reply configuration.

DlnSpiSlaveGetSupportedReplyModes()

Retrieves the supported reply modes.

DlnSpiSlaveSetReplyShortageAction()

Specifies actions if the reply buffer size is less than the size of the buffer received by the master.

DlnSpiSlaveGetReplyShortageAction()

Retrieves the current for reply shortage action settings.

DlnSpiSlaveGetSupportedShortageActions()

Retrieves the supported reply shortage actions.

Event configuration:

DlnSpiSlaveEnableSSRiseEvent()

Enables generating events when the level on the SS line rises.

DlnSpiSlaveDisableSSRiseEvent()

Disables generating events when the level on the SS line rises.

DlnSpiSlaveIsSSRiseEventEnabled()

Retrieves the current configuration for generating events when the level on the SS line rises.

DlnSpiSlaveEnableEvent()

Enables generating events when the buffer is full.

DlnSpiSlaveDisableEvent()

Disables generating events when the buffer is full.

DlnSpiSlaveIsEventEnabled()

Retrieves the current configuration for generating events when the buffer is full.

DlnSpiSlaveSetEventSize()

Specifies the buffer size.

DlnSpiSlaveGetEventSize()

Retrieves the current buffer size.

DlnSpiSlaveEnableIdleEvent()

Enables generating events when the slave idles for the configured time.

DlnSpiSlaveDisableEvent()

Disables generating events when the slave idles for the configured time.

DlnSpiSlaveIsEventEnabled()

Retrieves the current configuration for generating events when the slave idles for the configured time.

DlnSpiSlaveSetIdleEventTimeout()

Specifies the timeout value.

DlnSpiSlaveGetIdleEventTimeout()

Retrieves the current timeout value.

DlnSpiSlaveGetMinIdleEventTimeout()

Retrieves the minimum timeout value.

DlnSpiSlaveGetMaxIdleEventTimeout()

Retrieves the maximum timeout value.

The dln_spi_slave.h file declares the SPI Salve Interface functions.

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

DlnSpiSlaveGetPortCount() Function

The DlnSpiSlaveGetPortCount() function retrieves the total number of SPI slave ports available at your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetPortCount(
   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 the available SPI slave ports.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the port count successfully.

Remarks

The DlnSpiSlaveGetPortCount() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveEnable() Function

The DlnSpiSlaveEnable() function activates the specified SPI slave port at your DLN-series adapter.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

conflict

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

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

Return Value
DLN_RES_SUCCESS (0x00)

The function enabled the SPI slave module successfully.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_PIN_IN_USE (0xA5)

The port cannot be activated as the SPI slave 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_SPI_SLAVE_SS_IDLE_TIMEOUT (0xCB)

The port cannot be activated as the SPI slave port because its SS line is busy transmitting some data and was not released for time defined by the DlnSpiSlaveSetSSIdleTimeout() function.

Remarks

The DlnSpiSlaveEnable() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveDisable() Function

The DlnSpiSlaveDisable() function deactivates the specified SPI slave port on your DLN adapter.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

waitForTransferCompletion

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

  • 1 or DLN_SPI_SLAVE_WAIT_FOR_TRANSFERS - wait until transmissions complete.

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

Return Value
DLN_RES_SUCCESS (0x00)

The function disabled the SPI slave module successfully.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_TRANSFER_CANCELLED (0x20)

The pending transmissions were cancelled.

Remarks

The DlnSpiSlaveDisable() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveIsEnabled() Function

The DlnSpiSlaveIsEnabled() function retrieves information whether the specified SPI slave port is active or not.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

enabled

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

  • 0 or DLN_SPI_SLAVE_DISABLED - the port is not configured as a SPI slave.

  • 1 or DLN_SPI_SLAVE_ENABLED - the port is configured as a SPI slave.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved information about the port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveIsEnabled() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetSSIdleTimeout() Function

The DlnSpiSlaveSetSSIdleTimeout() function sets SS idle timeout. For details, read SS Idle Timeout.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveSetSSIdleTimeout(
    HDLN handle, 
    uint8_t port, 
    uint32_t timeout
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

The SS idle timeout value specified in milliseconds (ms). The minimum value is 1ms, the maximum value - 1000ms.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured SS idle timeout.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_TIMEOUT_VALUE (0xCA)

The SS idle timeout value is not valid.

Remarks

The default SS idle timeout value is set to 100ms.

The DlnSpiSlaveSetSSIdleTimeout() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSSIdleTimeout() Function

The DlnSpiSlaveGetSSIdleTimeout() function retrieves the current value of SS idle timeout.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

A pointer to an unsigned 32 bit integer that receives the current SS idle timeout value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current SS idle timeout value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSSIdleTimeout() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetFrameSize() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

frameSize

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

The frameSize parameter does not limit the size of the buffer transmitted to/from the SPI slave device, it only defines the minimum portion of data in this buffer.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully specified the frame size.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnSpiSlaveGetPortCount() 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 transmission.

DLN_RES_BUSY (0xB6)

The SPI slave is busy transmitting. The frame size cannot be changed.

Remarks

The DlnSpiSlaveSetFrameSize() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetFrameSize() Function

The DlnSpiSlaveGetFrameSize() function retrieves the current size setting for SPI data frames.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

frameSize

A pointer to unsigned 8-bit integer that receives the number of bits transmitted in a single frame. The DLN-series adapter supports 8 to 16 bits per frame.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current frame size.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetFrameSize() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedFrameSizes() Function

The DlnSpiSlaveGetSupportedFrameSizes() function returns all supported frame size values.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetSupportedFrameSizes(
    HDLN handle, 
    uint8_t port, 
    DLN_SPI_SLAVE_FRAME_SIZES *supportedSizes
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

supportedSizes

The pointer to the DLN_SPI_SLAVE_FRAME_SIZES structure that receives supported frame size values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved supported frame size values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSupportedFrameSizes() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetMode() Function

The DlnSpiSlaveSetMode() function sets SPI transmission parameters (CPOL and CPHA). For more information, read Clock Phase and Polarity.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave 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 special constants, defined in the dln_spi_slave.h file for each of the bits.

BitValueDescriptionConstant

0

0

CPOL=0

DLN_SPI_SLAVE_CPOL_0

0

1

CPOL=1

DLN_SPI_SLAVE_CPOL_1

1

0

CPHA=0

DLN_SPI_SLAVE_CPHA_0

1

1

CPHA=1

DLN_SPI_SLAVE_CPHA_1

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_MODE (0xC7)

The mode value is not valid. Use the DlnSpiSlaveGetSupportedModes() function to check the supported modes for the current SPI slave port.

DLN_RES_MUST_BE_DISABLED (0x95)

These configuration changes are allowed only when the module is disabled. Use the DlnSpiSlaveDisable() function to disable the SPI module before configuring the slave port.

Remarks

The DlnSpiSlaveSetMode() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetMode() Function

The DlnSpiSlaveGetMode() function retrieves the current transmission parameters (CPOL and CPHA) for the specified SPI slave port. For details, read Clock Phase and Polarity.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

mode

A pointer to an unsigned 8 bit integer that receives the SPI mode value. The bits 0 and 1 of this value correspond to CPOL and CPHA parameters respectively. The rest of the bits are not used.

BitValueDescriptionConstant

0

0

CPOL=0

DLN_SPI_SLAVE_CPOL_0

0

1

CPOL=1

DLN_SPI_SLAVE_CPOL_1

1

0

CPHA=0

DLN_SPI_SLAVE_CPHA_0

1

1

CPHA=1

DLN_SPI_SLAVE_CPHA_1

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetMode() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedModes() Function

The DlnSpiSlaveGetSupportedModes() function retrieves all supported SPI slave modes.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

values

The pointer to DLN_SPI_SLAVE_MODE_VALUES structure that receives all supported SPI slave mode values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the supported reply modes.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSupportedModes() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetCpha() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

cpha

The clock phase (CPHA) value. Can be 0 or 1.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_MUST_BE_DISABLED (0x95)

These configuration changes are allowed only when the module is disabled. Use the DlnSpiSlaveDisable() function to disable the SPI module before configuring the slave port.

DLN_RES_INVALID_CPHA (0xC9)

The provided CPHA value is not valid. Use the DlnSpiSlaveGetSupportedCphaValues() function to check the supported CPHA values for the current SPI slave port.

Remarks

The DlnSpiSlaveSetCpha() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetCpha() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

cpha

The pointer to uint8_t variable that receives the current CPHA value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetCpha() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedCphaValues() Function

The DlnSpiSlaveGetSupportedCphaValues() function retrieves all supported CPHA (clock phase) values.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

values

The pointer to DLN_SPI_SLAVE_CPHA_VALUES structure that receives all supported SPI slave CPHA values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

Remarks

The DlnSpiSlaveGetSupportedCphaValues() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetCpol() Function

The DlnSpiSlaveSetCpol() function allows to set the clock polarity (CPOL) value.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

cpol

The clock polarity (CPOL) value. Can be 0 or 1.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_MUST_BE_DISABLED (0x95)

These configuration changes are allowed only when the module is disabled. Use the DlnSpiSlaveDisable() function to disable the SPI module before configuring the slave port.

DLN_RES_INVALID_CPOL (0xC8)

The provided CPOL value is not valid. Use the DlnSpiSlaveGetSupportedCpolValues() function to check the supported CPOL values for the current SPI slave port.

Remarks

The DlnSpiSlaveSetCpol() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetCpol() Function

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

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

A handle to the DLN-series adapter.

port

A number of the SPI-slave port.

cpol

The pointer to uint8_t variable that receives the current CPOL value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetCpol() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedCpolValues() Function

The DlnSpiSlaveGetSupportedCpolValues() function retrieves all supported CPOL (clock polarity) values.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

values

The pointer to DLN_SPI_SLAVE_CPOL_VALUES structure that receives all supported CPOL values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the slave port mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSupportedCpolValues() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveLoadReply() Function

The DlnSpiSlaveLoadReply() function loads data (loads a number of bytes to reply buffer) to be transmitted to an SPI-master device. This function clears the buffer and makes the current reply the first in the queue.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

size

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

buffer

A pointer to an array of unsigned 8-bit integers (max 256-elements array). The buffer must contain the data to send to the SPI bus master.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully loaded data to reply buffer.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The buffer size is not valid. The DLN-series adapters support up to 256 bytes of the buffer.

DLN_RES_BUSY (0xB6)

The SPI slave is busy transmitting. Data cannot be loaded to the buffer.

Remarks

The DlnSpiSlaveLoadReply() function removes all replies from the queue and makes the current reply the first in the queue. In contrast, the DlnSpiSlaveEnqueueReply() function adds the reply to the queue.

The type of reply is configurable: it can be based on the SS line or based on the byte count. For details, read Reply Modes. To configure the reply mode, use the DlnSpiSlaveSetReplyMode() function.

The DlnSpiSlaveLoadReply() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveEnqueueReply() Function

The DlnSpiSlaveEnqueueReply() function adds a buffer to queue.

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

A handle to the DLN-series adapter.

port

A number of the SPI-slave port.

size

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

buffer

A pointer to an array of unsigned 8-bit integers (max 256-elements array). The buffer must contain the data to be sent to an SPI bus master.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully added data to reply queue.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The buffer size is not valid. The DLN-series adapters support up to 256 bytes of the buffer.

Remarks

If the queue is empty (after enabling), the DlnSpiSlaveEnqueueReply() function is equal to the DlnSpiSlaveLoadReply() function. If the queue is not empty, the DlnSpiSlaveEnqueueReply() function does not remove replies from the queue.

The DlnSpiSlaveEnqueueReply() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetReplyMode() Function

The DlnSpiSlaveSetReplyMode() function sets SPI slave reply mode.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

replyMode

Reply mode value. The following values are possible:

  • 0 or DLN_SPI_SLAVE_REPLY_MODE_OFF - No reply, transmitter is disabled.

  • 1 or DLN_SPI_SLAVE_REPLY_MODE_SS_BASED - Transmitting the reply stops when the SS line releases. If the reply was not transmitted completely, the rest part of the reply is lost. The next reply transmission starts after the new SS line assertion.

  • 2 or DLN_SPI_SLAVE_REPLY_MODE_COUNT_BASED - Only after the reply transmission is completed, the next reply can start. Transmission occurs regardless of the SS line state.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the reply mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_REPLY_TYPE (0xC5)

The specified reply type is not valid.

Remarks

The DLN_SPI_SLAVE_REPLY_MODE_COUNT_BASED reply mode allows to send data regardless of how many (or few) words are framed by the SS line. The DLN_SPI_SLAVE_REPLY_MODE_SS_BASED reply mode is set by default, it begins new data transmission/reply regardless of the data length. The DLN_SPI_SLAVE_REPLY_MODE_OFF mode disables transmission, it can be set for half-duplex write communication (for details, read SPI Data Transmission).

The DlnSpiSlaveSetReplyMode() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetReplyMode() Function

The DlnSpiSlaveGetReplyMode() function retrieves the current SPI slave reply mode.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetReplyMode(
    HDLN handle, 
    uint8_t port, 
    uint8_t *replyMode
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

replyMode

The pointer to an unsigned 8 bit integer that receives the SPI reply mode value after the function execution.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current reply mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetReplyMode() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedReplyModes() Function

The DlnSpiSlaveGetSupportedReplyModes() function retrieves the supported SPI slave reply modes.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetReplyMode(
    HDLN handle, 
    uint8_t port, 
    DLN_SPI_SLAVE_REPLY_MODES *supportedReplyModes
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

supportedReplyModes

The pointer to DLN_SPI_SLAVE_REPLY_MODES structure that receives all supported reply modes.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the supported reply mode.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSupportedReplyModes() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetReplyShortageAction() Function

The DlnSpiSlaveSetReplyShortageAction() function sets the reply shortage action value. When the master sends a data block that is larger than the loaded reply, this function specifies how to fill empty bytes (repeat the reply bytes or send zeroes).

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

action

Shortage action value to be set. There are 2 possible values:

  • DLN_SPI_SLAVE_REPLY_SHORTAGE_SEND_ZEROES - To fill the missed bytes with 0.

  • DLN_SPI_SLAVE_REPLY_SHORTAGE_REUSE - To fill the missed bytes repeating the reply.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the shortage action.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_BUSY (0xB6)

The SPI slave is busy transmitting. The reply shortage action cannot be changed. To change configuration, use the DlnSpiSlaveDisable() function.

Remarks

When the master sends a data block that is larger than the loaded reply, this function specifies how to fill empty bytes (repeat the reply bytes or send zeroes). For example, the loaded reply includes 3 bytes (11 22 33), but the master sends 5 bytes. If the function sets the DLN_SPI_SLAVE_REPLY_SHORTAGE_SEND_ZEROES value, the slave sends 11 22 33 00 00. If the function sets the DLN_SPI_SLAVE_REPLY_SHORTAGE_REUSE value, the slave sends 11 22 33 11 22. For details, read Reply Shortage Actions.

The DlnSpiSlaveSetReplyShortageAction() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetReplyShortageAction() Function

The DlnSpiSlaveGetReplyShortageAction() functions retrieves the current value of reply shortage action.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetReplyShortageAction(
    HDLN handle, 
    uint8_t port, 
    uint8_t *action
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

action

A pointer to unsigned 8-bit integer that receives the current reply shortage configuration.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current shortage configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetReplyShortageAction() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetSupportedShortageActions() Function

The DlnSpiSlaveGetSupportedShortageActions() function retrieves supported shortage action values.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveGetSupportedShortageActions(
    HDLN handle, 
    uint8_t port, 
    DLN_SPI_SLAVE_SHORTAGE_ACTIONS *supportedSizes
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI-slave port.

supportedSizes

The pointer to DLN_SPI_SLAVE_SHORTAGE_ACTIONS structure that receives all the supported shortage action values.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the supported shortage action values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetSupportedShortageActions() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveEnableSSRiseEvent() Function

The DlnSpiSlaveEnableSSRiseEvent() function activates event on SS rising edge.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the event on SS rising edge.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveEnableSSRiseEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveDisableSSRiseEvent() Function

The DlnSpiSlaveDisableSSRiseEvent() function deactivates SS rise events.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the event on SS rising edge.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveDisableSSRiseEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveIsSSRiseEventEnabled() Function

The DlnSpiSlaveIsSSRiseEventEnabled() function retrieves information whether the SS rise events are active or not.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port to retrieve the information from.

enabled

A pointer to an unsigned 8-bit integer that receives information whether the SS rise events are enabled.There are two possible values:

  • 0 or DLN_SPI_SLAVE_EVENT_DISABLED - SS rise events are not enabled.

  • 1 or DLN_SPI_SLAVE_EVENT_ENABLED - SS rise events are enabled.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the event on SS rising edge configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveIsSSRiseEventEnabled() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveEnableEvent() Function

The DlnSpiSlaveEnableEvent() function activates SPI slave buffer full event.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the SPI slave buffer full event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveEnableEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveDisableEvent() Function

The DlnSpiSlaveDisableEvent() function deactivates SPI slave buffer full event.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the SPI slave buffer full event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveDisableEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveIsEventEnabled() Function

The DlnSpiSlaveIsEventEnabled() function retrieves information whether the SPI slave events are active or not.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port to retrieve the information from.

enabled

A pointer to an unsigned 8-bit integer that receives information whether the SPI slave port events are activated or not. There are two possible values:

  • 0 or DLN_SPI_SLAVE_EVENT_DISABLED - SPI slave events are enabled.

  • 1 or DLN_SPI_SLAVE_EVENT_ENABLED - SPI slave events are disabled.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieves the SPI slave buffer full event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveIsEventEnabled() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetEventSize() Function

The DlnSpiSlaveSetEventSize() function sets the event buffer size.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port to be configured.

size

Event buffer size parameter. Its value can vary from 1 to 256 bytes.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the event buffer size.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The buffer size is not valid. The DLN-series adapters support up to 256 bytes of the buffer.

Remarks

The DlnSpiSlaveSetEventSize() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetEventSize() Function

The DlnSpiSlaveGetEventSize() function retrieves value of current event buffer size.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port to retrieve the SPI buffer size value from.

size

A pointer to an unsigned 16 bit integer that receives the current event buffer size value. The value varies from 1 to 256.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current event buffer size.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetEventSize() function is defined in dln_spi_slave.h file.

DlnSpiSlaveEnableIdleEvent() Function

The DlnSpiSlaveEnableIdleEvent() function activates the SPI slave idle event.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the SPI slave idle event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_EVENT_TYPE (0xA9)

The idle event conflicts with the SS rise event. To enable the idle event, disable the SS rise event by using the DlnSpiSlaveDisableSSRiseEvent() function.

Remarks

The DlnSpiSlaveEnableIdleEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveDisableIdleEvent() Function

The DlnSpiSlaveDisableIdleEvent() function deactivates the SPI slave idle event.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the SPI slave idle event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveDisableIdleEvent() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveIsIdleEventEnabled() Function

The DlnSpiSlaveIsIdleEventEnabled() function activates the SPI slave idle event.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

enabled

A pointer to an unsigned 8-bit integer that receives information whether the idle events are activated or not.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the SPI slave idle event.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveIsIdleEventEnabled() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveSetIdleEventTimeout() Function

The DlnSpiSlaveSetIdleEventTimeout() function sets idle event timeout.

Syntax
C/C++
DLN_RESULT DlnSpiSlaveSetIdleEventTimeout(
    HDLN handle, 
    uint8_t port, 
    uint32_t timeout
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

The idle event timeout value specified in milliseconds (ms).

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured idle event timeout.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_TIMEOUT_VALUE (0xCA)

The idle event timeout value is not valid.

Remarks

The default idle event timeout value is set to 0ms.

The DlnSpiSlaveSetIdleEventTimeout() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetIdleEventTimeout() Function

The DlnSpiSlaveGetIdleEventTimeout() function retrieves the current value of idle event timeout.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

A pointer to an unsigned 32 bit integer that receives the current idle event timeout value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the minimum idle event timeout value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetIdleEventTimeout() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetMinIdleEventTimeout() Function

The DlnSpiSlaveGetMinIdleEventTimeout() function retrieves the minimum value of idle event timeout.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

A pointer to an unsigned 32 bit integer that receives the minimum idle event timeout value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the maximum idle event timeout value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetMinIdleEventTimeout() function is defined in the dln_spi_slave.h file.

DlnSpiSlaveGetMaxIdleEventTimeout() Function

The DlnSpiSlaveGetMaxIdleEventTimeout() function retrieves the maximum value of idle event timeout.

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

A handle to the DLN-series adapter.

port

A number of the SPI slave port.

timeout

A pointer to an unsigned 32 bit integer that receives the minimum idle event timeout value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the maximum idle event timeout value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnSpiSlaveGetMaxIdleEventTimeout() function is defined in the dln_spi_slave.h file.