I2C总线是由Philips公司开发的一种简单、双向二线制同步串行总线。它只需要两根线即可在连接于总线上的器件之间传送信息。
To control multi-master IIC-bus operations, values must be written to the following registers:
— Multi-master IIC-bus control register, IICCON
— Multi-master IIC-bus control/status register, IICSTAT
— Multi-master IIC-bus Tx/Rx data shift register, IICDS
— Multi-master IIC-bus address register, IICADD
控制I2C总线,需要设置一下寄存器,IICCON IICSTAT IICDS IICADD
When the IIC-bus is free, the SDA and SCL lines should be both at High level. A High-to-Low transition of SDA
can initiate a Start condition. A Low-to-High transition of SDA can initiate a Stop condition while SCL remains
steady at High Level.
总线空闲时,SDA和SCL为高电平。当SCL为高电平时,SDA由高到低表示START信号,SDA由低到高表示STOP信号,如下图所示
When a master initiates a Start condition, it should send a slave address to notify the slave device. One byte of
address field consists of a 7-bit address and a 1-bit transfer direction indicator (showing write or read).
If bit 8 is 0, it indicates a write operation (transmit operation); if bit 8 is 1, it indicates a request for data read
(receive operation).
当总线发出一个START信号后,总线需要传输一个7bit的从机地址和一位的读写位。0表示write,1表示read
例如:从机地址为0x68,需要执行的操作是读,那么需要发送的SLAVE_ADDRESS = (0x68 << 1) | 0x1;
Every byte placed on the SDA line should be eight bits in length. The bytes can be unlimitedly transmitted per
transfer. The first byte following a Start condition should have the address field. The address field can be
transmitted by the master when the IIC-bus is operating in Master mode. Each byte should be followed by an
acknowledgement (ACK) bit. The MSB bit of the serial data and addresses are always sent first.
i2c总线传输单位为byte,i2c每次传输完成后从设备都需要回复一个ack信号,告知master设备数据已经接收完成,如下图所示