English
Language : 

UPSD3422_06 Datasheet, PDF (130/293 Pages) STMicroelectronics – Turbo Plus Series Fast Turbo 8032 MCU with USB and Programmable Logic
I2C interface
uPSD34xx
Enable All Interrupts and go do something else
– SFR IE.EA = 1
23.13.1
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 interrupts.
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 variable, status
– status = S1STA
Read global variables that determine the mode
– mode <= (I2C_master, I2C_slave)
If mode is Master-Transmitter
Bus Arbitration lost? (status.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? (status.ACK_RESP=0?)
If No, an ACK was not received:
– S1CON.STO = 1, set STOP bus condition
– <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 condition
<STOP occurs after ISR exit>
– S1DAT = dummy, write to release bus
– Exit ISR
130/293