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.