This is the quickstart guide for the SAM TWIS driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.
Basic use case
The basic use case demonstrate how to initialize the TWIS module and configure it.
Prerequisites
- System Clock Management (Sysclock)
Setup steps
Example code
Enable the following macro in the conf_clock.h:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC0
Add the following code in the application C-file:
Workflow
- Set system clock source as DFLL:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
- Set DFLL source as OSC0:
- Initialize the system clock.
Usage steps
Example code
Add to, e.g., main loop in application C-file:
slave_callbacks.
rx = TWIS_RX_HANDLER_POINTER;
slave_callbacks.
tx = TWIS_TX_HANDLER_POINTER;
slave_callbacks.
stop = TWIS_STOP_HANDLER_POINTER;
slave_callbacks.
error = TWIS_ERROR_HANDLER_POINTER;
Workflow
- Initialize the TWIS module with the given self slave address SLAVE_ADDRESS:
- Set up the callback functions to handle reception, transmission, STOP condition and errors. In the end, enable the slave address match interrupt:
slave_callbacks.
rx = TWIS_RX_HANDLER_POINTER;
slave_callbacks.
tx = TWIS_TX_HANDLER_POINTER;
slave_callbacks.
stop = TWIS_STOP_HANDLER_POINTER;
slave_callbacks.
error = TWIS_ERROR_HANDLER_POINTER;
- Enable TWIS module: