
566
SAM G51 [DATASHEET]
11209C–ATARM–20-Dec-13
4.
(Master Only) Write the START bit in the TWIHS_CR to start the transfer.
5.
Wait for the PDC ENDRX flag either by using polling method or ENDRX interrupt.
6.
Disable the PDC by setting the PDC RXTDIS bit.
7.
Wait for the RXRDY flag in TWIHS_SR.
8.
Set the STOP command in TWIHS_CR to end the transfer.
9.
Read the penultimate character in TWIHS_RHR.
10. Wait for the RXRDY flag in TWIHS_SR.
11. Read the last character in TWIHS_RHR.
12. (Optional) Wait for the TXCOMP flag in TWIHS_SR before disabling the peripheral clock if required.
27.7.3.10 SMBus Mode
SMBus mode is enabled when the SMEN bit is written to one in the TWIHS_CR. SMBus mode operation is similar to IC
operation with the following exceptions:
1.
Only 7-bit addressing can be used.
2.
The SMBus standard describes a set of timeout values to ensure progress and throughput on the bus. These time-
out values must be programmed into TWIHS_SMBTR.
3.
Transmissions can optionally include a CRC byte, called Packet Error Check (PEC).
4.
A dedicated bus line, SMBALERT, allows a slave to get a master attention.
5.
A set of addresses has been reserved for protocol handling, such as alert response address (ARA) and host
header (HH) address. Address matching on these addresses can be enabled by configuring the TWIHS_CR
appropriately.
Packet Error Checking
Each SMBus transfer can optionally end with a CRC byte, called the PEC byte. Writing the PECEN bit in TWIHS_CR to
one enables automatic PEC handling in the current transfer. Transfers with and without PEC can freely be intermixed in
the same system, since some slaves may not support PEC. The PEC LFSR is always updated on every bit transmitted or
received, so that PEC handling on combined transfers will be correct.
In master transmitter mode, the master calculates a PEC value and transmits it to the slave after all data bytes have been
transmitted. Upon reception of this PEC byte, the slave will compare it to the PEC value it has computed itself. If the
values match, the data was received correctly, and the slave will return an ACK to the master. If the PEC values differ,
data was corrupted, and the slave will return a NACK value. Some slaves may not be able to check the received PEC in
time to return a NACK if an error occurred. In this case, the slave should always return an ACK after the PEC byte, and
some other mechanism must be implemented to verify that the transmission was received correctly.
In master receiver mode, the slave calculates a PEC value and transmits it to the master after all data bytes have been
transmitted. Upon reception of this PEC byte, the master will compare it to the PEC value it has computed itself. If the
values match, the data was received correctly. If the PEC values differ, data was corrupted, and the PECERR bit in
TWIHS_SR is set. In master receiver mode, the PEC byte is always followed by a NACK transmitted by the master, since
it is the last byte in the transfer.
In combined transfers, the PECRQ bit should only be set in the last of the combined transfers. .
Consider the following transfer:
S, ADR+W, COMMAND_BYTE, ACK, SR, ADR+R, DATA_BYTE, ACK, PEC_BYTE, NACK, P
Timeouts
The TLOWS and TLOWM fields in TWIHS_SMBTR configure the SMBus timeout values. If a timeout occurs, the master
will transmit a STOP condition and leave the bus. The TOUT bit is also set in TWIHS_SR.
27.7.3.11 SMBUS Quick Command (Master Mode Only)
The TWI interface can perform a quick command: