Справочник Пользователя для Freescale Semiconductor Demonstration Board for Freescale MC9S12XHY256 Microcontroller DEMO9S12XHY256 DEMO9S12XHY256

Модели
DEMO9S12XHY256
Скачать
Страница из 924
Inter-Integrated Circuit (IICV3) Block Description
MC9S12XHY-Family Reference Manual, Rev. 1.04
416
Freescale Semiconductor
If a master receiver wants to terminate a data transfer, it must inform the slave transmitter by not
acknowledging the last byte of data which can be done by setting the transmit acknowledge bit (TXAK)
before reading the 2nd last byte of data. Before reading the last byte of data, a STOP signal must be
generated first. The following is an example showing how a STOP signal is generated by a master receiver.
12.7.1.5
Generation of Repeated START
At the end of data transfer, if the master continues to want to communicate on the bus, it can generate
another START signal followed by another slave address without first generating a STOP signal. A
program example is as shown.
12.7.1.6
Slave Mode
In the slave interrupt service routine, the module addressed as slave bit (IAAS) should be tested to check
if a calling of its own address has just been received. If IAAS is set, software should set the transmit/receive
mode select bit (Tx/Rx bit of IBCR) according to the R/W command bit (SRW). Writing to the IBCR
clears the IAAS automatically. Note that the only time IAAS is read as set is from the interrupt at the end
of the address cycle where an address match occurred, interrupts resulting from subsequent data transfers
will have IAAS cleared. A data transfer may now be initiated by writing information to IBDR, for slave
transmits, or dummy reading from IBDR, in slave receive mode. The slave will drive SCL low in-between
byte transfers, SCL is released when the IBDR is accessed in the required mode.
In slave transmitter routine, the received acknowledge bit (RXAK) must be tested before transmitting the
next byte of data. Setting RXAK means an 'end of data' signal from the master receiver, after which it must
be switched from transmitter mode to receiver mode by software. A dummy read then releases the SCL
line so that the master can generate a STOP signal.
MASTX
TST
TXCNT
;GET VALUE FROM THE TRANSMITING COUNTER
BEQ
END
;END IF NO MORE DATA
BRSET
IBSR,#$01,END
;END IF NO ACK
MOVB
DATABUF,IBDR
;TRANSMIT NEXT BYTE OF DATA
DEC
TXCNT
;DECREASE THE TXCNT
BRA
EMASTX
;EXIT
END
BCLR
IBCR,#$20
;GENERATE A STOP CONDITION
EMASTX
RTI
;RETURN FROM INTERRUPT
MASR
DEC
RXCNT
;DECREASE THE RXCNT
BEQ
ENMASR
;LAST BYTE TO BE READ
MOVB
RXCNT,D1
;CHECK SECOND LAST BYTE
DEC
D1
;TO BE READ
BNE
NXMAR
;NOT LAST OR SECOND LAST
LAMAR
BSET
IBCR,#$08
;SECOND LAST, DISABLE ACK
;TRANSMITTING
BRA
NXMAR
ENMASR
BCLR
IBCR,#$20
;LAST ONE, GENERATE ‘STOP’ SIGNAL
NXMAR
MOVB
IBDR,RXBUF
;READ DATA AND STORE
RTI
RESTART
BSET
IBCR,#$04
;ANOTHER START (RESTART)
MOVB
CALLING,IBDR
;TRANSMIT THE CALLING ADDRESS;D0=R/W