English
Language : 

MC68HC12 Datasheet, PDF (319/478 Pages) Motorola, Inc – The MC68HC912DT128A microcontroller unit (MCU) is a 16-bit device composed of standard on-chip peripherals including a 16-bit central processing unit
Inter IC Bus
IIC Programming Examples
17.7.2 Generation of START
After completion of the initialization procedure, serial data can be
transmitted by selecting the 'master transmitter' mode. If the device is
connected to a multi-master bus system, the state of the IIC Bus Busy
bit (IBB) must be tested to check whether the serial bus is free.
If the bus is free (IBB=0), the start condition and the first byte (the slave
address) can be sent. The data written to the data register comprises the
slave calling address and the LSB set to indicate the direction of transfer
required from the slave.
The bus free time (i.e., the time between a STOP condition and the
following START condition) is built into the hardware that generates the
START cycle. Depending on the relative frequencies of the system clock
and the SCL period it may be necessary to wait until the IIC is busy after
writing the calling address to the IBDR before proceeding with the
following instructions. This is illustrated in the following example.
An example of a program which generates the START signal and
transmits the first byte of data (slave address) is shown below:
CHFLAG
TXSTART
IBFREE
BRSET
BSET
MOVB
BRCLR
IBSR,#$20,*
IBCR,#$30
CALLING,IBDR
IBSR,#$20,*
;WAIT FOR IBB FLAG TO CLEAR
;SET TRANSMIT AND MASTER MODE
;i.e. GENERATE START CONDITION
;TRANSMIT THE CALLING
;ADDRESS, D0=R/W
;WAIT FOR IBB FLAG TO SET
17.7.3 Post-Transfer Software Response
Transmission or reception of a byte will set the data transferring bit (TCF)
to 1, which indicates one byte communication is finished. The IIC Bus
interrupt bit (IBIF) is set also; an interrupt will be generated if the interrupt
function is enabled during initialization by setting the IBIE bit. Software
must clear the IBIF bit in the interrupt routine first. The TCF bit will be
cleared by reading from the IIC Bus Data I/O Register (IBDR) in receive
mode or writing to IBDR in transmit mode.
Software may service the IIC I/O in the main program by monitoring the
IBIF bit if the interrupt function is disabled. Note that polling should
MC68HC912DT128A — Rev 4.0
MOTOROLA
Inter IC Bus
Technical Data
319