#include "globals.h"
Go to the source code of this file.
Defines | |
#define | I2C_ACK 1 |
Constant used by i2c_send_ack to send an acknowledge. | |
#define | I2C_NO_ACK 0 |
Constant used by i2c_send_ack to send no acknowledge. | |
#define | I2C_MASK_WRITE 0xfe |
Bitmask used when writing data to a device. | |
#define | I2C_MASK_READ 0x01 |
Bitmask used when reading data from a device. | |
#define | I2C_READ(ADDRESS) (ADDRESS | I2C_MASK_READ) |
Set the device address r/w bit. | |
#define | I2C_WRITE(ADDRESS) (ADDRESS & I2C_MASK_WRITE) |
Clear the device address r/w bit. | |
Functions | |
void | i2c_init (void) |
Initialize the electric i2c interface. | |
void | i2c_start (void) |
Send a start sequence on the bus. | |
void | i2c_stop (void) |
Send a stop sequence on the bus. | |
u08 | i2c_send_byte (u08 data) |
Send a byte over the bus. | |
u08 | i2c_read_byte (void) |
Read a byte from the bus. | |
void | i2c_send_ack (u08 ack) |
Send an acknowledge / no acknowledge bit over the bus. |
In this version, the i2c bus interface methods can handle one master and multiple slaves. Currently there is no support for clock synchronization and arbitration. (It is not even planned to implement this)
See http://www.philips.com "The I2C bus and how to use it" for an introduction to the I2C protocol.
|
Bitmask used when reading data from a device. Has to be or-ed to the device address. Better use the I2C_READ macro. |
|
Bitmask used when writing data to a device. Has to be and-ed to the device address. Better use the I2C_WRITE macro. |
|
Set the device address r/w bit. This macro ensures that the r/w bit that is send after the device address is set to indicate reading |
|
Clear the device address r/w bit. This macro ensures that the r/w bit that is send after the device address is cleared to indicate writing |
|
Initialize the electric i2c interface. This method sets the i/o pins defined in i2c.c to input / output and issues a stop condition to the bus so that the bus is in a defined state after calling this method. |
|
Read a byte from the bus. As i2c_send_byte(u08 data) this method does nothing more than reading a byte from the bus and returning it. |
|
Send a byte over the bus. This method sends no start / stop sequence or device address but only the data byte, i.e. i2c_start() and i2c_stop() have to be called seperately. A often used sequence could be
for sending one byte, a command for example, to a device. |