Jump to main content
18.8.3.2.2 Workflow
Configure and enable module:
void
configure_i2c_slave(
void
)
{
struct
i2c_slave_config config_i2c_slave;
i2c_slave_get_config_defaults(&config_i2c_slave);
config_i2c_slave.address = SLAVE_ADDRESS;
config_i2c_slave.address_mode = I2C_SLAVE_ADDRESS_MODE_MASK;
config_i2c_slave.buffer_timeout = 1000 ;
i2c_slave_init(&i2c_slave_instance, CONF_I2C_SLAVE_MODULE, &config_i2c_slave);
i2c_slave_enable(&i2c_slave_instance);
}
Create and initialize configuration structure.
struct
i2c_slave_config config_i2c_slave;
i2c_slave_get_config_defaults(&config_i2c_slave);
Change settings in the configuration.
config_i2c_slave.address = SLAVE_ADDRESS;
config_i2c_slave.address_mode = I2C_SLAVE_ADDRESS_MODE_MASK;
config_i2c_slave.buffer_timeout = 1000 ;
Initialize the module with the set configurations.
i2c_slave_init(&i2c_slave_instance, CONF_I2C_SLAVE_MODULE, &config_i2c_slave);
Enable the module.
i2c_slave_enable(&i2c_slave_instance);
Configure DMA
Create a DMA resource configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
struct
dma_resource_config config;
Initialize the DMA resource configuration struct with the module's default values.
dma_get_config_defaults(&config);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
Set extra configurations for the DMA resource. It is using peripheral trigger. SERCOM RX trigger causes a beat transfer in this example.
config.peripheral_trigger = CONF_I2C_DMA_TRIGGER;
config.trigger_action = DMA_TRIGGER_ACTON_BEAT;
Allocate a DMA resource with the configurations.
dma_allocate(resource, &config);
Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
struct
dma_descriptor_config descriptor_config;
Initialize the DMA transfer descriptor configuration struct with the module's default values.
dma_descriptor_get_config_defaults(&descriptor_config);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
descriptor_config.beat_size = DMA_BEAT_SIZE_BYTE;
descriptor_config.src_increment_enable =
false
;
descriptor_config.block_transfer_count = DATA_LENGTH;
descriptor_config.destination_address = (uint32_t)read_buffer + DATA_LENGTH;
descriptor_config.source_address =
(uint32_t)(&i2c_slave_instance.hw->I2CS.DATA.reg);
Create the DMA transfer descriptor.
dma_descriptor_create(descriptor, &descriptor_config);
The online versions of the documents are provided as a courtesy. Verify all content and data in the device’s PDF documentation found on the device product page.