HT56R66/HT56R666
I2C Control Register - SIMAR
The SIMARregister is also used by the SPI interface but
has the name SIMCTL2.
The SIMARregister is the location where the 7-bit slave
address of the microcontroller is stored. Bits 1~7 of the
SIMAR register define the microcontroller slave ad-
dress. Bit 0 is not defined. When a master device, which
is connected to the I2C bus, sends out an address,
which matches the slave address in the SIMARregister,
the microcontroller slave device will be selected. Note
that the SIMAR register is the same register as
SIMCTL2 which is used by the SPI interface.
S ta rt
W r ite S la v e
A d d re s s to S IM A R
S E T S IM [2 :0 ]= 1 1 0
S E T S IM E N
D is a b le
C LR E H I
P o ll H IF to d e c id e
w h e n to g o to I2C B u s IS R
I2C B u s
In te rru p t= ?
E n a b le
SET EHI
W a it fo r In te r r u p t
I2C Bus Communication
Communication on the I2C bus requires four separate
steps, a START signal, a slave device address transmis-
sion, a data transmission and finally a STOP signal.
When a START signal is placed on the I2C bus, all de-
vices on the bus will receive this signal and be notified of
the imminent arrival of data on the bus. The first seven
bits of the data will be the slave address with the first bit
being the MSB. If the address of the microcontroller
matches that of the transmitted address, the HAAS bit in
the SIMCTL1 register will be set and an I2C interrupt will
be generated. After entering the interrupt service rou-
tine, the microcontroller slave device must first check
the condition of the HAAS bit to determine whether the
interrupt source originates from an address match or
from the completion of an 8-bit data transfer. During a
data transfer, note that after the 7-bit slave address has
been transmitted, the following bit, which is the 8th bit, is
the read/write bit whose value will be placed in the SRW
bit. This bit will be checked by the microcontroller to de-
termine whether to go into transmit or receive mode. Be-
fore any transfer of data to or from the I2C bus, the
microcontroller must initialise the bus, the following are
steps to achieve this:
Step 1
Write the slave address of the microcontroller to the I2C
bus address register SIMAR.
Step 2
Set the SIMEN bit in the SIMCTL0 register to ²1² to en-
able the I2C bus.
Step 3
Set the ESIM bit of the interrupt control register to en-
able the I2C bus interrupt.
G o to M a in P r o g r a m
G o to M a in P r o g r a m
I2C Bus Initialisation Flow Chart
· Start Signal
The START signal can only be generated by the mas-
ter device connected to the I2C bus and not by the
microcontroller, which is only a slave device. This
START signal will be detected by all devices con-
nected to the I2C bus. When detected, this indicates
that the I2C bus is busy and therefore the HBB bit will
be set. A START condition occurs when a high to low
transition on the SDA line takes place when the SCL
line remains high.
· Slave Address
The transmission of a START signal by the master will
be detected by all devices on the I2C bus. To deter-
mine which slave device the master wishes to com-
municate with, the address of the slave device will be
sent out immediately following the START signal. All
slave devices, after receiving this 7-bit address data,
will compare it with their own 7-bit slave address. If the
address sent out by the master matches the internal
address of the microcontroller slave device, then an
internal I2C bus interrupt signal will be generated. The
next bit following the address, which is the 8th bit, de-
fines the read/write status and will be saved to the
SRW bit of the SIMCTL1 register. The device will then
transmit an acknowledge bit, which is a low level, as
the 9th bit. The microcontroller slave device will also
set the status flag HAAS when the addresses match.
As an I2C bus interrupt can come from two sources,
when the program enters the interrupt subroutine, the
HAAS bit should be examined to see whether the in-
terrupt source has come from a matching slave ad-
dress or from the completion of a data byte transfer.
When a slave address is matched, the device must be
placed in either the transmit mode and then write data
to the SIMDR register, or in the receive mode where it
must implement a dummy read from the SIMDR regis-
ter to release the SCL line.
b7
b0
SA6 SA5 SA4 SA3 SA2 SA1 SA0
S IM A R R e g is te r
N o t im p le m e n te d , r e a d a s " 0 "
I2 C d e v ic e s la v e a d d r e s s
I2C Slave Address Register - SIMAR
Rev. 1.40
62
May 11, 2012