This documents describe the usage of the driver for the TWI (Two-Wire Interface) ® Master on the Atmel SAM4 family of devices. It describes usage in an I compatible manner and does not provide any guidence for the use of SMBus.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of Atmel may not be used to endorse or promote products derived from this software without specific prior written permission.
Module Overview This driver provides access to the main features of the TWIM controller. The two wire interface connects components via a two-wire serial bus, each device, on the bus, has a unique ID. The TWI modules are programmable as masters with sequential or single-byte access. High speed mode capability is also supported.
API Overview Variable and Type Definitions 4.1.1 Type twim_transfer_status_t typedef enum twim_transfer_status twim_transfer_status_t twim_transfer_status for enumeration definitions. 4.1.2 Type twim_callback_t typedef void(* twim_callback_t )(Twim *) Structure Definitions 4.2.1 Struct twim_config This is the configuration structure for the TWI Master device. It is used as an argument for twim_set_config provide the desired configurations for the module.
Macro Definitions 4.3.1 TWI Driver Compatibility These codes are defined for SAM devices to simplify the porting of existing code from other Atmel devices. For the definition of technical terms and acronyms refer to Acronyms and the appropriate device datasheet.
4.3.1.4 Macro twi_probe #define twi_probe 4.3.2 Macro TWI_FAST_MODE_PLUS_SPEED #define TWI_FAST_MODE_PLUS_SPEED TWI Fast Mode Plus mode. 4.3.3 Macro TWI_FAST_MODE_SPEED #define TWI_FAST_MODE_SPEED Value to set TWI to Fast speed mode. 4.3.4 Macro TWI_HIGH_SPEED_MODE_SPEED #define TWI_HIGH_SPEED_MODE_SPEED Value to set TWI to High speed plus mode. 4.3.5 Macro TWI_STD_MODE_SPEED #define TWI_STD_MODE_SPEED...
#define TWIM_LOW_POWER_ENABLE Enable TWIM Low Power Transfer by default. 4.3.9 Macro TWIM_SCR_NAK_MASK #define TWIM_SCR_NAK_MASK Mask to clear the DNAK and ANAK bits in the Status Clear register. 4.3.10 Macro TWIM_SR_NAK_MASK #define TWIM_SR_NAK_MASK Status Register mask to test for NAKs in data or address phase. 4.3.11 Macro TWIM_SR_STD_MASK #define TWIM_SR_STD_MASK...
status_code_t twi_master_write( Twim * twim, struct twim_package * package) Table 4-5. Parameters Data direction Parameter name Description [in] twim Base address of the TWIM [in] package Package information and data Table 4-6. Return Values Return value Description STATUS_OK If all bytes were send successfully ERR_IO_ERROR NACK received or Bus Arbitration lost 4.4.3...
Twim * twim) Table 4-9. Parameters Data direction Parameter name Description [in] twim Base address of the TWIM instance 4.4.6 Function twim_disable_interrupt() Disable the TWIM interrupts and clear their status. void twim_disable_interrupt( Twim * twim, uint32_t interrupt_source) Write the value passed in interrupt_source into the Interrupt Disable Register. Each bit clears the corresponding bit in the Interrupt Mask Register and the Status Clear Register.
Data direction Parameter name Description [in] interrupt_source The TWI interrupt to be enabled 4.4.9 Function twim_get_interrupt_mask() Return the current content of the Interrupt Mask Register. uint32_t twim_get_interrupt_mask( Twim * twim) Table 4-13. Parameters Data direction Parameter name Description [in] twim Base address of the TWIM Returns TWIM interrupt mask.
Data direction Parameter name Description [in] read True if it's a read trasnfer 4.4.12 Function twim_probe() Test if a device answers for a given TWI address. status_code_t twim_probe( Twim * twim, uint32_t chip_addr) Table 4-16. Parameters Data direction Parameter name Description [in] twim...
Table 4-19. Parameters Data direction Parameter name Description [in] twim Base address of the TWIM [in] config Options for initializing the TWIM module Table 4-20. Return Values Return value Description STATUS_OK Transaction is successful ERR_INVALID_ARG Invalid arg resulting in wrong CWGR Exponential 4.4.15 Function twim_set_hsmode_speed() Set the TWI bus speed in conjunction with the clock frequency in high speed mode.
Data direction Parameter name Description [in] The current running system clock frequency [in] cycles Clock cycles for data setup count Table 4-24. Return Values Return value Description STATUS_OK Transaction is successful ERR_INVALID_ARG Invalid arg resulting in wrong CWGR Exponential Enumeration Definitions 4.5.1 Enum twim_transfer_status Table 4-25.
Extra Information Acronyms Term Definition Status Clear Register Negative Acknowledgement DNAK Negative Acknowledgement int TWI data phase ANAK Negative Acknowledgement int TWI address phase ARBLST Arbitration lost to a higher priority bus master in TWI multi-master mode Interupt Enable Register AT07334: SAM4 TWI Master Mode Driver [APPLICATION NOTE] 42274A-MCU-05/2014...
TWIM Master Example Purpose This is an example of how to use the TWIM driver to access an EEPROM. Requirements The program needs a TWI-compatible EEPROM connected as shown below: Connections for Board: SAM4L Xplained Pro Board EEPROM TWIMS3 TWD(PB14,EXT2/PIN11 TWIMS3 TWCK(PB15,EXT2/PIN12) Connections for Board: SAM4L-EK...
Quick Start Guide This is the quick start guide for the SAM4 TWI Master Mode Driver, with step-by-step instructions on how to configure and use the driver for a specific use case.The code examples can be copied into the main application loop or any other function that will need to control the TWIM module.
Note The read/write functions will enable and disable the corresponding interrupt sources. Usage Steps 8.4.1 twim_basic_usage_code We can send data to the target slave device. Firstly, the data package should be prepared. In one data package, several items should be set; the target slave address, the internal address (if needed), the length of the internal address (if needed), the data buffer to be written, and the length of the data buffer.
Page 26
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.