
232
CHAPTER 12 I2C Interface
MB89960 series
12.7 Program Example for the I2C Interface
This section gives program examples for the I2C interface.
s Program Example for the Master Transmit Mode
q Processing description
Generates serial clock rate at 100 kbit/s.
Use System Management Bus input buffer characteristic.
Set in master transmit mode.
Transmit data 64H to slave with address 19H.
The following shows the ICCR register value that results in a serial clock rate Fsck of
approximately 100 kbit/s for a source oscillation Fc of 10 MHz.
where
Finst = 10MHz / 2 / 2 = 2.5MHz
m is selected by CS4 and CS3 and
n is selected by CS2,CS1 and CS0 in ICCR register.
m x n = 5 MHz /100 KHz - 4 = 46 (approximately 6 x 8)
So ICCR register value (bit 4 to bit 0) is 01000B , and ICCR: DMBP (bit 7) is 0B.
q Coding example
IBSR
EQU
0010H
;Address of the I2C bus status register
IBCR
EQU
0011H
;Address of the I2C bus control register
ICCR
EQU
0012H
;Address of the I2C clock control register
IADR
EQU
0013H
;Address of the I2C address register
IDAR
EQU
0014H
;Address of the I2C data register
EN
EQU
ICCR:5
;Defines the I2C enable bit.
BER
EQU
IBCR:7
;Defines the bus error interrupt request flag bit.
INT
EQU
IBCR:0
;Defines the data transfer completed interrupt request flag bit.
ILR3
EQU
007EH
;Address of interrupt level setting register 3
INT_V
DSEG
ABS
;[DATA SEGMENT]
ORG
0FFEAH
IRQ8
DW
WARI
;Set interrupt vector.
INT_V
ENDS
;-----Main program---------------------------------------------------------------------------------------------------------------------------------------
CSEG
;[CODE SEGMENT]
;Stack pointer (SP) etc. are already initialized.
:
CLRI
;Disable interrupts.
SETB
EN
Enable I2C operation.
MOV
ILR3,#11111101B
;Set interrupt level (level 1).
MOV
ICCR,#028H
;Enable I2C operation and select shift clock frequency as
100KHz, use SMB interface
SETI
;and enable interrupts.
MOV
IADR,#10110010B
;Set its own specific address as B2H.
MOV
IDAR,#00110010B
;Send calling address as 19H and R/W bit as write.
MOV
IBCR,#01011110B
;Enable interrupt request flags and set as master mode with
;acknowledge enable
STA_CON
MOV
A,#01110110B
;Wait for generating START condition and first byte transfer
Fsck
2Finst
mn
4
+
×
-----------------------
=