English
Language : 

UPSD33XX Datasheet, PDF (109/231 Pages) STMicroelectronics – Fast 8032 MCU with Programmable Logic
Slave-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 = 0, I2C_xmitter = 1
Enable SIOE
– SFR S1CON.INI1 = 1
Prepare to Xmit first data byte
– SFR S1DAT[7:0] = xmit_buf[0]
Enable All Interrupts and go do some-
thing else
– SFR IE.EA = 1
Slave-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 = 0, I2C_xmitter = 0
Enable SIOE
– SFR S1CON.INI1 = 1
Enable All Interrupts and go do some-
thing else
– SFR IE.EA = 1
uPSD33xx
Interrupt Service Routine (ISR). A typical I2C
interrupt service routine would handle a interrupt
for any of the four combinations of Master/Slave
and Transmitter/Receiver. In the example routines
above, the firmware sets global variables,
I2C_master and I2C_xmitter, before enabling in-
terrupts. These flags tell the ISR which one of the
four cases to process. Following is pseudo-code
for high-level steps in the I2C ISR:
Begin I2C ISR <I2C interrupt just occurred>:
Clear I2C interrupt flag:
– S1STA.INTR = 0
Read status of SIOE, put in to vari-
able, status
– status = S1STA
Read global variables that determine
the mode
– mode <= (I2C_master, I2C_slave)
If mode is Master-Transmitter
Bus Arbitration lost? (sta-
tus.BLOST=1?)
If Yes, Arbitration was lost:
– S1DAT = dummy, write to release bus
– Exit ISR, SIOE will switch to Slave
Recv mode
If No, Arbitration was not
lost, continue:
ACK recvd from Slave? (sta-
tus.ACK_RESP=0?)
If No, an ACK was not received:
– S1CON.STO = 1, set STOP bus condi-
tion
– <STOP occurs after ISR exit>
– S1DAT = dummy, write to release bus
– Exit ISR
If Yes, ACK was received, then
continue:
– S1DAT = xmit_buf[buffer_index],
transmit byte
Was that the last byte of data to
transmit?
If No, it was not the last byte,
then:
– Exit ISR, transmit next byte on
next interrupt
If Yes, it was the last byte,
then:
– S1CON.STO = 1, set STOP bus condi-
tion
<STOP occurs after ISR exit>
– S1DAT = dummy, write to release bus
– Exit ISR
109/231