112
ATtiny25/45/85 [DATASHEET]
2586Q–AVR–08/2013
sbrs
r16, USIOIF
rjmp
SlaveSPITransfer_loop
in
r16,USIDR
ret
The code is size optimized using only eight instructions (plus return). The code example assumes that the DO and
USCK pins have been enabled as outputs in DDRB. The value stored in register r16 prior to the function is called is
transferred to the master device, and when the transfer is completed the data received from the master is stored
back into the register r16.
Note that the first two instructions is for initialization, only, and need only be executed once. These instructions set
three-wire mode and positive edge clock. The loop is repeated until the USI Counter Overflow Flag is set.
15.3.4
Two-wire Mode
The USI two-wire mode is compliant to the Inter IC (TWI) bus protocol, but without slew rate limiting on outputs and
without input noise filtering. Pin names used in this mode are SCL and SDA.
Figure 15-4. Two-wire Mode Operation, Simplified Diagram
Figure 15-4 shows two USI units operating in two-wire mode, one as master and one as slave. It is only the physi-
cal layer that is shown since the system operation is highly dependent of the communication scheme used. The
main differences between the master and slave operation at this level is the serial clock generation which is always
done by the master. Only the slave uses the clock control unit.
Clock generation must be implemented in software, but the shift operation is done automatically in both devices.
Note that clocking only on negative edges for shifting data is of practical use in this mode. The slave can insert wait
states at start or end of transfer by forcing the SCL clock low. This means that the master must always check if the
SCL line was actually released after it has generated a positive edge.
MASTER
SLAVE
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SDA
SCL
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Two-wire Clock
Control Unit
HOLD
SCL
PORTxn
SDA
SCL
VCC