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).
To provide the I2C communication, you need to configure the I2C slave port:
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.
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.
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.
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.
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:
If you want your DLN I2C slave port to acknowledge the general call addressing, call the DlnI2cSlaveGeneralCallEnable() function.
If you want your DLN I2C slave port to ignore the general call addressing, call the DlnI2cSlaveGeneralCallDisable() function.
To check the current configuration of the general call support, use the DlnI2cSlaveGeneralCallIsEnabled() function.
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:
| A DLN adapter does not generate any I2C events. |
| A DLN adapter generates events when the I2C master device initiates receiving data from the I2C slave address assigned to the DLN adapter. The |
| A DLN adapter generates events when the I2C master device initiates transmitting data to the I2C slave address assigned to the DLN adapter. The |
| 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 |
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.
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.
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)
.
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.
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)
.
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.
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)
.
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:
Retrieves the total number of I2C slave ports available at your DLN-series adapter.
Assigns a port to the I2C Slave module.
Releases a port from the I2C Slave module.
Retrieves whether a port is assigned to the I2C Slave module.
Loads data to be transmitted to an I2C master device.
I2C Slave module configuration functions:
Activates I2C general call support.
Disables I2C general call support.
Retrieves whether I2C general call support is activated.
Retrieves the number of I2C slave addresses supported by the DLN adapter.
Assigns an I2C slave address to the specified I2C slave module.
Retrieves one of the I2C slave addresses assigned to the specified I2C slave module.
I2C Slave event functions:
Configures event generation for an I2C slave port.
Retrieves event generation configuration for an I2C slave port.
Retrieves the list of event types available for an I2C slave port.
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.
The DlnI2cSlaveEnable()
function activates the specified I2C slave port at your DLN-series adapter.
The DlnI2cSlaveGeneralCallDisable()
function disables the I2C general call support to make this slave ignore general call addressing.
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.
The DlnI2cSlaveGeneralCallIsEnabled()
function checks whether I2C general call support is enabled for the specified I2C slave port.
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.
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.
The DlnI2cSlaveGetEvent()
function retrieves settings for I2C event generation for the specified I2C slave port and I2C slave address.
The DlnI2cSlaveGetPortCount()
function retrieves the total number of I2C slave ports available in your DLN-series adapter.
The DlnI2cSlaveGetSupportedEventTypes()
function returns all supported I2C slave event types for opened DLN-series adapter.
The DlnI2cSlaveIsEnabled()
function checks whether the specified I2C slave port is active or not.
The DlnI2cSlaveLoadReply()
function loads data to be transferred to an I2C master device.
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.
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.
This section describes the structures used for I2C events. These structures are declared in the dln_i2c_slave.h
file.
The DLN_I2C_SLAVE_READ_EV
structure contains information about the I2C read event.
The DLN_I2C_SLAVE_WRITE_EV
structure contains information about the I2C write event.