14.7.3 Master transmitter
Main software prepares to write/read data to/from the Slave I2C device. The software has to be ready
to get number of data with internal RAM or sending data on internal RAM according to I2C bus
protocol type of the Slave device.
It writes salve address to I2CDR register in the I2C block, then, if it sets a START bit of the I2CMR
register, the I2C block sends the slave address with SCL clock to the Slave device. The I2C block
takes master mode (MASTER bit -> 1) and takes the read/write state (TMODE bit, read (0), write (1))
according to the data direction bit (R/Wî¡) of device address.
Example software for the master mode is introduced below:
Master write
I2CMR = IICEN+INTEN; // set I2C block( enable IIC block, I2C interrupt)
I2CDR = Slave Address + Write mode; // load target Salve Address
I2CMR |= SRT; // generate start condition and send slave address
I2C interrupt service
If(Master Mode) and (TMODE)
If( ACK and GCALL or ACK and TEND )
If ( Not End of Data )
I2CDR = NEXT DATA; // load target Salve Address
I2CSR = 0xFF; // Byte transmit start
ELSE
I2CMR = IICEN+INTEN+STP; // STOP generation
ELSE
Initialize I2C block // if have ACK error, any error
End of I2C interrupt service