I2C Slave Interface

Some DLN-series adapters support I2C slave interface.

Before you activate the I2C slave port, you need to configure it (See Configuring I2C Slave Interface).

You can configure events to be informed when an I2C master receives data from your slave and/or transmits data to it (See I2C Slave Events).

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

Configuring I2C Slave Interface

To provide the I2C communication, you need to configure the I2C slave port:

  1. Specify the I2C slave address of your device. DLN adapters support 7-bit addressing. Some DLN adapters allow to specify several I2C slave addresses. For details, read I2C Slave Addressing.

  2. Configure general call support. I2C slave can ignore or acknowledge the general call addressing when data can be transmitted to all I2C slaves simultaneously. For details, read General Call Support.

  3. Configure generating events. Events can be generated when an I2C master initiates data transmission. If you do not need these notifications, cancel generating events. Read I2C Slave Events.

After you have finished configuring the I2C slave device, enable the I2C slave port by the DlnI2cSlaveEnable() function.

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

I2C Slave Addressing

DLN adapters support only 7-bit addressing. To assign a I2C slave address to your device, use the DlnI2cSlaveSetAddress() function. This function does not prevent you from assigning reserved addresses to your DLN adapter. For more information about reserved addresses, read Reserved I2C Slave Addresses.

Some DLN adapters can support more than one I2C slave addresses simultaneously. To check how many I2C slave addresses are supported by your DLN adapter, use the DlnI2cSlaveGetAddressCount() function. To assign several I2C slave addresses to your DLN adapter, use the DlnI2cSlaveSetAddress() function for every address. In the function, you specify the slaveAddressNumber parameter; its value should be unique for every I2C slave address but should not exceed the number of supported slave addresses.

To check an I2C slave address assigned to your device, call the DlnI2cSlaveGetAddress() function and point the desired value of the slaveAddressNumber parameter. To check all assigned I2C slave addresses, call the DlnI2cSlaveGetAddress() function for every possible slaveAddressNumber value.

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

General Call Support

I2C bus allows to transmit data to all I2C slaves simultaneously. This option is called General Call. To make a general call, the I2C master generates the following address: 0000 000 followed by the Write (0) direction bit. The General Call address is one of the reserved addresses and cannot be assigned to any I2C slave device.

When an I2C slave receives the general call address, it can acknowledge it to receive transmitted data or ignore it.

You can configure the I2C slave’s behavior when it receives the general call address:

To check the current configuration of the general call support, use the DlnI2cSlaveGeneralCallIsEnabled() function.

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

I2C Slave Events

There are two ways to detect an I2C transmission:

  • To observe I2C lines permanently. This consumes much CPU time. Besides, the more times the device polls the I2C bus, the less time it can spend carrying out its intended function. That is why such devices are slow.

  • To receive events about the requests from the I2C bus. You can configure event generation when the I2C master addresses for receiving or transmitting data.

To configure events, use the DlnI2cSlaveSetEvent() function. You need to specify the slaveAddressNumber and eventType parameters. The DlnI2cSlaveGetSupportedEventTypes() function returns the list of event types available for the I2C slave port.

The eventType parameter can have one of the following values:

I2C Events Types

DLN_I2C_SLAVE_EVENT_NONE

A DLN adapter does not generate any I2C events.

DLN_I2C_SLAVE_EVENT_READ

A DLN adapter generates events when the I2C master device initiates receiving data from the I2C slave address assigned to the DLN adapter. The DLN_I2C_SLAVE_READ_EV structure describes the event details. Read DLN_I2C_SLAVE_EVENT_READ Events

DLN_I2C_SLAVE_EVENT_WRITE

A DLN adapter generates events when the I2C master device initiates transmitting data to the I2C slave address assigned to the DLN adapter. The DLN_I2C_SLAVE_WRITE_EV structure describes the event details. Read DLN_I2C_SLAVE_EVENT_WRITE Events

DLN_I2C_SLAVE_EVENT_READ_WRITE

A DLN adapter generates events when the I2C master device initiates receiving data from or transmitting data to the I2C slave address assigned to the DLN adapter. The DLN_I2C_SLAVE_READ_EV structure describes the read event details. The DLN_I2C_SLAVE_WRITE_EV structure describes the write event details. Read DLN_I2C_SLAVE_EVENT_READ_WRITE Events

By default, event generation is disabled for all I2C slave addresses (the eventType parameter is set to DLN_I2C_SLAVE_EVENT_NONE).

If your DLN adapter uses more than one I2C slave address, you can specify different event configuration for each I2C slave address.

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

DLN_I2C_SLAVE_EVENT_READ Events

A DLN adapter generates the DLN_I2C_SLAVE_EVENT_READ events each time the I2C master device initiates receiving data from the I2C slave address assigned to the DLN adapter.

DLN_I2C_SLAVE_EVENT_READ event

Use the DlnI2cSlaveSetEvent() function to configure events. Pass DLN_I2C_SLAVE_EVENT_READ for the eventType parameter.

The DLN_I2C_SLAVE_READ_EV structure describes the event details: event counter, I2C slave address and port number, and the buffer size. The header of the structure contains the msgId field that is set to DLN_MSG_ID_I2C_SLAVE_READ_EV (0x0C10).

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

DLN_I2C_SLAVE_EVENT_WRITE Events

A DLN adapter generates the DLN_I2C_SLAVE_EVENT_WRITE events each time the I2C master device initiates transmitting data to the I2C slave address assigned to the DLN adapter.

DLN_I2C_SLAVE_EVENT_WRITE event

Use the DlnI2cSlaveSetEvent() function to configure events. Pass DLN_I2C_SLAVE_EVENT_WRITE for the eventType parameter.

The DLN_I2C_SLAVE_WRITE_EV structure describes the event details: event counter, I2C slave address and port number, the buffer size and the received data. The header of the structure contains the msgId field that is set to DLN_MSG_ID_I2C_SLAVE_WRITE_EV (0x0C11).

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

DLN_I2C_SLAVE_EVENT_READ_WRITE Events

A DLN adapter generates the DLN_I2C_SLAVE_EVENT_READ_WRITE events each time the I2C master device initiates receiving data from or transmitting data to the I2C slave address assigned to the DLN adapter.

DLN_I2C_SLAVE_EVENT_READ_WRITE events

Use the DlnI2cSlaveSetEvent() function to configure events. Pass DLN_I2C_SLAVE_EVENT_READ_WRITE for the eventType parameter.

The DLN_I2C_SLAVE_EVENT_READ_WRITE events are described by two structures:

  • The DLN_I2C_SLAVE_READ_EV structure describes the I2C read event details: event counter, I2C slave address and port number, and the buffer size. The header of the structure contains the msgId field that is set to DLN_MSG_ID_I2C_SLAVE_READ_EV (0x0C10).

  • The DLN_I2C_SLAVE_WRITE_EV structure describes the I2C write event details: event counter, I2C slave address and port number, the buffer size and the received data. The header of the structure contains the msgId field that is set to DLN_MSG_ID_I2C_SLAVE_WRITE_EV (0x0C11).

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

I2C Slave Functions

Use the I2C Slave Interface functions to control and monitor the I2C Slave module of a DLN-series adapter. The dln_i2c_slave.h file declares the I2C Slave Interface functions.

General port information:

DlnI2cSlaveGetPortCount()

Retrieves the total number of I2C slave ports available at your DLN-series adapter.

DlnI2cSlaveEnable()

Assigns a port to the I2C Slave module.

DlnI2cSlaveDisable()

Releases a port from the I2C Slave module.

DlnI2cSlaveIsEnabled()

Retrieves whether a port is assigned to the I2C Slave module.

DlnI2cSlaveLoadReply()

Loads data to be transmitted to an I2C master device.

I2C Slave module configuration functions:

DlnI2cSlaveGeneralCallEnable()

Activates I2C general call support.

DlnI2cSlaveGeneralCallDisable()

Disables I2C general call support.

DlnI2cSlaveGeneralCallIsEnabled()

Retrieves whether I2C general call support is activated.

DlnI2cSlaveGetAddressCount()

Retrieves the number of I2C slave addresses supported by the DLN adapter.

DlnI2cSlaveSetAddress()

Assigns an I2C slave address to the specified I2C slave module.

DlnI2cSlaveGetAddress()

Retrieves one of the I2C slave addresses assigned to the specified I2C slave module.

I2C Slave event functions:

DlnI2cSlaveSetEvent()

Configures event generation for an I2C slave port.

DlnI2cSlaveGetEvent()

Retrieves event generation configuration for an I2C slave port.

DlnI2cSlaveGetSupportedEventTypes()

Retrieves the list of event types available for an I2C slave port.

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

DlnI2cSlaveDisable() Function

The DlnI2cSlaveDisable() function deactivates the specified I2C slave port at your DLN-series adapter and releases the pins previously used for SDA and SCL lines.

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

waitForTransferCompletion

The parameter that contains your choice according the function behavior if the I2C slave port is busy transmitting data. The following values are possible:

  • DLN_I2C_SLAVE_WAIT_FOR_TRANSFERS(1) - Wait until the transmission completes.

  • DLN_I2C_SLAVE_CANCEL_TRANSFERS(0) - Cancel all pending data transmissions and disable the module.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully deactivated the I2C slave port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_TRANSFER_CANCELLED (0x20)

The function cancelled the pending data transmission.

Remarks

The DlnI2cSlaveDisable() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveEnable() Function

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

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

conflict

A number of the pin that is currently occupied by another module. To fix this, check which module uses the pin (call the DlnGetPinCfg()function), disconnect the pin from that module and call the DlnI2cSlaveEnable() function once again.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the I2C slave port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_PIN_IN_USE (0xA5)

At least one pin of the port is assigned to another module. The conflict parameter contains the number of the conflicting pin.

DLN_RES_I2C_SLAVE_ADDRESS_NEEDED (0xBE)

The I2C slave address is not specified for this device. Use the DlnI2cSlaveSetAddress() function to specify the address.

Remarks

The I2C bus interface requires two lines for data transmission and synchronization (SDA and SCL). If any of these lines is used by another module, the DLN adapter cannot activate the I2C slave port. The DlnI2cSlaveEnable() function returns only one conflicting pin. If both SCL and SDA lines are in use, you need to call this function three times: two times to detect both conflicting pins and the third time to enable the I2C slave port.

The DlnI2cSlaveEnable() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGeneralCallDisable() Function

The DlnI2cSlaveGeneralCallDisable() function disables the I2C general call support to make this slave ignore general call addressing.

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disabled the general call support.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGeneralCallDisable()function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGeneralCallEnable() Function

The DlnI2cSlaveGeneralCallEnable() function activates I2C general call support. With general call all I2C slave devices on the circuit can be addressed by sending zero as I2C slave address.

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully enabled the general call support.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGeneralCallEnable() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGeneralCallIsEnabled() Function

The DlnI2cSlaveGeneralCallIsEnabled() function checks whether I2C general call support is enabled for the specified I2C slave port.

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

enabled

A pointer to an unsigned 8-bit integer that receives information whether general call support is enabled. There are two possible values:

  • DLN_I2C_SLAVE_GENERAL_CALL_DISABLED (0) - The I2C slave port ignores the general call address.

  • DLN_I2C_SLAVE_GENERAL_CALL_ENABLED (1) - The 2C slave port acknowledges the general call address and receives transmitted data.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved whether the general call support is enabled.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGeneralCallIsEnabled() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGetAddress() Function

The DlnI2cSlaveGetAddress() function retrieves one of the I2C slave addresses, assigned to the specified I2C slave module. The total number of simultaneously assigned addresses can be retrieved with the DlnI2cSlaveGetAddressCount() function.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveGetAddress(
   HDLN handle,
   uint8_t port,
   uint8_t slaveAddressNumber,
   uint8_t* address
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

slaveAddressNumber

A number of the I2C slave address to be retrieved. The slaveAddressNumber value can be in the range from 0 up to (but not including) the value returned by the DlnI2cSlaveGetAddressCount() function.

address

A pointer to an unsigned 8-bit integer that receives the I2C slave address.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the I2C slave address.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGetAddress() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGetAddressCount() Function

The DlnI2cSlaveGetAddressCount() function retrieves the number of I2C slave addresses supported by the DLN adapter.

DLN-series adapters can acknowledge any I2C slave address. The limitation is only in the amount of slave addresses to be used simultaneously. You can use the DlnI2cSlaveSetAddress() function to configure the I2C slave module to acknowledge specific addresses.

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

A handle to the DLN-series adapter

port

A number of the I2C slave port.

count

A pointer to an unsigned 8-bit integer that receives the number of supported I2C slave addresses.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of possible slave addresses.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGetAddressCount() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGetEvent() Function

The DlnI2cSlaveGetEvent() function retrieves settings for I2C event generation for the specified I2C slave port and I2C slave address.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveGetEvent(
   HDLN handle,
   uint8_t port,
   uint16_t slaveAddressNumber
   uint8_t* eventType,
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

slaveAddressNumber

A number of the I2C slave address to retrieve settings for. Use the DlnI2cSlaveGetAddressCount() function to obtain the total number of supported I2C slave addresses.

eventType

A pointer to an unsigned 8-bit integer that receives the current event generation settings. The following values are supported:

  • I2C_SLAVE_EVENT_NONE (0) - No I2C slave events are generated.

  • I2C_SLAVE_EVENT_READ (1) - I2C slave events are generated when an I2C master device reads data from the PC-I2C adapter.

  • I2C_SLAVE_EVENT_WRITE (2) - I2C slave events are generated when an I2C master device writes data to the PC-I2C adapter.

  • I2C_SLAVE_EVENT_READ_WRITE (1) - I2C slave events are generated both for read and write transactions.

Refer to I2C Slave Events section for additional information.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current I2C slave events configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveGetEvent() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGetPortCount() Function

The DlnI2cSlaveGetPortCount() function retrieves the total number of I2C slave ports available in your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveGetPortCount(
   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 I2C slave ports.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of I2C slave ports.

Remarks

The DlnI2cSlaveGetPortCount() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveGetSupportedEventTypes() Function

The DlnI2cSlaveGetSupportedEventTypes() function returns all supported I2C slave event types for opened DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveGetSupportedEventTypes(
    HDLN handle, 
    uint8_t port, 
    DLN_I2C_SLAVE_EVENT_TYPES *supportedEventTypes
);
Parameters
handle

A handle to the DLN-series adapter.

port

I2C slave port number.

supportedEventTypes

The pointer to DLN_I2C_SLAVE_EVENT_TYPES structure that receives the supported event types.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the supported I2C slave events.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

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

DlnI2cSlaveIsEnabled() Function

The DlnI2cSlaveIsEnabled() function checks whether the specified I2C slave port is active or not.

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

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

enabled

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

  • DLN_I2C_SLAVE_DISABLED (0) - The I2C slave port is inactive.

  • DLN_I2C_SLAVE_ENABLED (1) - The I2C slave port is active.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved information.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnI2cSlaveIsEnabled() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveLoadReply() Function

The DlnI2cSlaveLoadReply() function loads data to be transferred to an I2C master device.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveLoadReply(
   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 I2C slave port.

size

A size of the data buffer to be loaded. The size is specified as a number bytes and can vary from 1 to 256.

buffer

A pointer to an array of unsigned 8-bit integers that receives data to be sent to an I2C master. The size of the buffer is specified in the size parameter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully loaded data to the buffer.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_BUSY (0xB6)

The function cannot specify I2C slave addresses for the DLN adapter while the I2C slave port is busy transmitting data.

DLN_RES_INVALID_BUFFER_SIZE (0xAE)

The specified buffer size is not valid.

Remarks

The DlnI2cSlaveLoadReply() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveSetAddress() Function

The DlnI2cSlaveSetAddress() function assigns I2C addresses to the specified I2C slave module. You can assign any 7-bit address, the limitation is only in quantity of addresses that can be used simultaneously. Use the DlnI2cSlaveGetAddressCount() function to retrieve the number of simultaneously supported I2C slave addresses.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveSetAddress(
   HDLN handle,
   uint8_t port,
   uint8_t slaveAddressNumber,
   uint8_t address
);
Parameters
handle

A handle to the DLN-series adapter.

port

An I2C slave port to be configured.

slaveAddressNumber

A number of the I2C slave address to be assigned. Use the DlnI2cSlaveGetAddressCount()function to retrieve the number of simultaneously supported I2C slave addresses. The slaveAddressNumber is zero based.

address

An I2C slave address to be set to the specified I2C slave port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully specified I2C slave addresses for your DLN adapter.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_BUSY (0xB6)

The function cannot specify I2C slave addresses for the DLN adapter while the I2C slave port is busy transmitting data.

DLN_RES_INVALID_ADDRESS (0xB4)

The I2C slave address is not valid.

Remarks

The DlnI2cSlaveSetAddress() function is defined in the dln_i2c_slave.h file.

DlnI2cSlaveSetEvent() Function

The DlnI2cSlaveSetEvent() function configures the I2C slave events generation conditions for the specified I2C slave port and I2C slave address.I2C slave events can vary for different I2C slave addresses. Specify the number of the I2C slave address in the slaveAddressNumber parameter.

Syntax
C/C++
DLN_RESULT DlnI2cSlaveSetEvent(
   HDLN handle,
   uint8_t port,
   uint8_t slaveAddressNumber,
   uint8_t eventType,
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the I2C slave port.

slaveAddressNumber

A number of the I2C slave address. The slaveAddressNumber parameter is zero base. Possible value are from zero up to (but not including) the value returned by the DlnI2cSlaveGetAddressCount() function.

eventType

A condition for I2C slave event generation. The following values are available:

  • I2C_SLAVE_EVENT_NONE (0) - No I2C slave events are generated.

  • I2C_SLAVE_EVENT_READ (1) - I2C slave events are generated when an I2C master device reads data from the PC-I2C adapter.

  • I2C_SLAVE_EVENT_WRITE (2) - I2C slave events are generated when an I2C master device writes data to the PC-I2C adapter.

  • I2C_SLAVE_EVENT_READ_WRITE (3) - I2C slave events are generated both for read and write transactions.

For additional details, read the I2C Slave Events section.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured I2C slave events.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_BUSY (0xB6)

The function cannot configure I2C slave addresses for the DLN adapter while the I2C slave port is busy transmitting data.

DLN_RES_INVALID_EVENT_TYPE (0xA9)

The specified event type is not valid. Use the DlnI2cSlaveGetSupportedEventTypes() function to check the list of supported I2C slave events.

Remarks

The DlnI2cSlaveSetEvent() function is defined in the dln_i2c_slave.h file.

I2C Event Structures

This section describes the structures used for I2C events. These structures are declared in the dln_i2c_slave.h file.

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

DLN_I2C_SLAVE_READ_EV Structure

The DLN_I2C_SLAVE_READ_EV structure contains information about the I2C read event.

Syntax
C/C++
typedef struct
{
        DLN_MSG_HEADER header;
        uint16_t eventCount;
        uint8_t eventType;
        uint8_t port;
        uint8_t slaveAddress;
        uint16_t size;
} __PACKED_ATTR DLN_I2C_SLAVE_READ_EV;
Event Structure Members
header

Defines the DLN message header. It should have the following value: DLN_MSG_ID_I2C_SLAVE_READ_EV (0x0C10).

eventCount

The number of events generated after the event configuration changed.

eventType

The type of generating events. The following values are possible:

ValueConstantDescription

1

DLN_I2C_SLAVE_EVENT_READ

Events are generated when the I2C master initiates receiving data from the I2C slave device.

3

DLN_I2C_SLAVE_EVENT_READ_WRITE

Events are generated when the I2C master initiates receiving data from or transmitting data to the I2C slave device.

port

The number of the I2C slave port where the event is generated.

slaveAddress

The I2C slave address assigned to the DLN adapter that generated the event.

size

A size of the buffer that stores the event data.

DLN_I2C_SLAVE_WRITE_EV Structure

The DLN_I2C_SLAVE_WRITE_EV structure contains information about the I2C write event.

Syntax
C/C++
typedef struct
{
        DLN_MSG_HEADER header;
        uint16_t eventCount;
        uint8_t eventType;
        uint8_t port;
        uint8_t slaveAddress;
        uint16_t size;
        uint8_t buffer[DLN_I2C_SLAVE_BUFFER_SIZE];
} __PACKED_ATTR DLN_I2C_SLAVE_WRITE_EV;
Event Structure Members
header

Defines the DLN message header. It should have the following value: DLN_MSG_ID_I2C_SLAVE_WRITE_EV (0x0C10).

eventCount

The number of events generated after the event configuration changed.

eventType

The type of generating events. The following values are possible:

ValueConstantDescription

2

DLN_I2C_SLAVE_EVENT_WRITE

Events are generated when the I2C master initiates transmitting data from the I2C slave device.

3

DLN_I2C_SLAVE_EVENT_READ_WRITE

Events are generated when the I2C master initiates receiving data from or transmitting data to the I2C slave device.

port

The number of the I2C slave port where the event is generated.

slaveAddress

The I2C slave address assigned to the DLN adapter that generated the event.

size

A size of the buffer that stores the event data.

buffer

The buffer that contains data received from the I2C master.