
565
SAM G51 [DATASHEET]
11209C–ATARM–20-Dec-13
Program TWIHS_IADR with b3 b4 b5 b6 b7 b8 b9 b10 (b10 is the LSB of the 10-bit address)
Figure 27-15 shows a byte write to an Atmel AT24LC512 EEPROM. This demonstrates the use of internal addresses to
access the device.
Figure 27-15.
Internal Address Usage
27.7.3.7
Repeated Start
In addition to internal address mode, repeated start (Sr) can be generated manually by writing the START bit at the end
of a transfer instead of the STOP bit. In such case the parameters of the next transfer (direction, SADR, etc.) will need to
be set before writing the START bit at the end of the previous transfer.
Note that generating a repeated start after a single data read is not supported.
27.7.3.8
Bus Clear Command
The TWI interface can perform a Bus Clear Command:
1.
Configure the master mode (DADR, CKDIV, etc).
2.
Start the transfer by setting the CLEAR bit in the TWIHS_CR.
27.7.3.9
Using the Peripheral DMA Controller (PDC) in Master Mode
The use of the PDC significantly reduces the CPU load.
To assure correct implementation, respect the following programming sequences:
Data Transmit with the PDC in Master Mode
The PDC transfer size must be defined with the buffer size minus 1. The remaining character must be managed without
PDC to ensure that the exact number of bytes are transmitted regardless of system bus latency conditions during the end
of the buffer transfer period.
1.
Initialize the transmit PDC (memory pointers, transfer size - 1).
2.
Configure the master mode (DADR, CKDIV, etc.).
3.
Start the transfer by setting the PDC TXTEN bit.
4.
Wait for the PDC ENDTX flag either by using the polling method or ENDTX interrupt.
5.
Disable the PDC by setting the PDC TXTDIS bit.
6.
Wait for the TXRDY flag in TWIHS_SR.
7.
Set the STOP command in TWIHS_CR.
8.
Write the last character in TWIHS_THR.
9.
(Optional) Wait for the TXCOMP flag in TWIHS_SR before disabling the peripheral clock if required.
Data Receive with the PDC in Master Mode
The PDC transfer size must be defined with the buffer size minus 2. The two remaining characters must be managed
without PDC to ensure that the exact number of bytes are received regardless of system bus latency conditions during
the end of the buffer transfer period.
1.
Initialize the receive PDC (memory pointers, transfer size - 2).
2.
Configure the master mode (DADR, CKDIV, etc.).
3.
Set the PDC RXTEN bit.
S
T
A
R
T
M
S
B
Device
Address
0
L
S
B
R
/
W
A
C
K
M
S
B
W
R
I
T
E
A
C
K
A
C
K
L
S
B
A
C
K
FIRST
WORD ADDRESS
SECOND
WORD ADDRESS
DATA
S
T
O
P