|
UPSD33XX Datasheet, PDF (108/231 Pages) STMicroelectronics – Fast 8032 MCU with Programmable Logic | |||
|
◁ |
uPSD33xx
I2C Operating Sequences
The following pseudo-code explains hardware
control for these I2C functions on the uPSD33xx:
â Initialize the Interface
â Function as Master-Transmitter
â Function as Master-Receiver
â Function as Slave-Transmitter
â Function as Slave-Receiver
â Interrupt Service Routine
Full C code drivers for the uPSD33xx I2C inter-
face, and other interfaces are available from the
web at www.st.com\psm.
Initialization after a uPSD33xx reset
Ensure pins P3.6 and P3.7 are GPIO in-
puts
â SFR P3.7 = 1 and SFR P3.6 = 1
Configure pins P3.6 and P3.7 as I2C
â SFR P3SFS.6 = 1 and P3SFS.7 = 1
Set I2C clock prescaler to determine
fSCL
â SFR S1CON.CR[2:0] = desired SCL
freq.
Set bus START condition sampling
â SFR S1SETUP[7:0] = number of sam-
ples
Enable individual I2C interrupt and
set priority
â SFR IEA.I2C = 1
â SFR IPA.I2C = 1 if high priority is
desired
Set the Device address for Slave mode
â SFR S1ADR = XXh, desired address
Enable SIOE (as Slave) to return an
ACK signal
â SFR S1CON.AA = 1
Master-Transmitter
Disable all interrupts
â SFR IE.EA = 0
Set pointer to global data xmit buff-
er, set count
â *xmit_buf = *pointer to data
â buf_length = number of bytes to
xmit
Set global variables to indicate Mas-
ter-Xmitter
â I2C_master = 1, I2C_xmitter = 1
Disable Master from returning an ACK
â SFR S1CON.AA = 0
Enable I2C SIOE
â SFR S1CON.INI1 = 1
Transmit Address and R/W bit = 0 to
Slave
â Is bus not busy? (SFR S1STA.BBUSY
= 0?)
<If busy, then test until not busy>
â SFR S1DAT[7:0] = Load Slave Ad-
dress & FEh
â SFR S1CON.STA = 1, send START on
bus
<bus transmission begins>
Enable All Interrupts and go do some-
thing else
â SFR IE.EA = 1
Master-Receiver
Disable all interrupts
â SFR IE.EA = 0
Set pointer to global data recv buff-
er, set count
â *recv_buf = *pointer to data
â buf_length = number of bytes to
recv
Set global variables to indicate Mas-
ter-Xmitter
â I2C_master = 1, I2C_xmitter = 0
Disable Master from returning an ACK
â SFR S1CON.AA = 0
Enable I2C SIOE
â SFR S1CON.INI1 = 1
Transmit Address and R/W bit = 1 to
Slave
â Is bus not busy? (SFR S1STA.BBUSY
= 0?)
<If busy, then test until not busy>
â SFR S1DAT[7:0] = Load Slave Ad-
dress # 01h
â SFR S1CON.STA = 1, send START on
bus
<bus transmission begins>
Enable All Interrupts and go do some-
thing else
â SFR IE.EA = 1
108/231
|
▷ |