27.2 Overview
The Two-Wire Interface (TWI) peripheral is a bidirectional, two-wire communication interface. It is I2C and System Management Bus (SMBus) compatible. The only external hardware needed to implement the bus is one pull-up resistor on each bus line.
Any device connected to the bus must act as a master or a slave. The master initiates a data transaction by addressing a slave on the bus and telling whether it wants to transmit or receive data. One bus can have many slaves and one or several masters that can take control of the bus. An arbitration process handles priority if more than one master tries to transmit data at the same time. Mechanisms for resolving bus contention are inherent in the protocol.
The TWI peripheral supports master and slave functionality. The master and slave functionality are separated from each other and can be enabled and configured separately. The master module supports multi-master bus operation and arbitration. It contains the Baud Rate Generator. All 100 kHz, 400 kHz, and 1 MHz bus frequencies are supported. Quick command and Smart mode can be enabled to auto-trigger operations and reduce software complexity.
The slave module implements 7-bit address match and general address call recognition in hardware. 10-bit addressing is supported. A dedicated Address Mask register can act as a Second Address match register or as a register for address range masking. The slave continues to operate in all Sleep modes, including Power-Down mode. This enables the slave to wake-up the device from all Sleep modes on TWI address match. It is possible to disable the address matching to let this be handled in software instead.
The TWI peripheral will detect Start and Stop conditions, bus collisions, and bus errors. Arbitration lost, errors, collision, and clock hold on the bus are also detected and indicated in separate status flags available in both Master and Slave modes.
This device provides one instance of the TWI peripheral; TWI0.