simple i2c library
v0.85
Covers I2C basics like start/stop conditions and byte & data send & receive
|
#include "simplei2c.h"
Functions | |
HUBTEXT i2c * | i2c_open (i2c *bus, int sclPin, int sdaPin, int sclDrive) |
Open an i2c device. More... | |
HUBTEXT void | i2c_start (i2c *bus) |
Signal i2c start condition on bus. More... | |
HUBTEXT void | i2c_stop (i2c *bus) |
Send Signal i2c stop condition on bus. More... | |
HUBTEXT int | i2c_writeByte (i2c *bus, int byte) |
Send i2c byte and return acknowledgement from device. Does not set start or stop. Drives SCL line if i2c device opened using sclDrive = 1. More... | |
HUBTEXT int | i2c_readByte (i2c *bus, int ackState) |
Receive i2c byte and reply with ack state. Does not set start or stop. Drives SCL line if i2c device opened using sclDrive = 1. More... | |
HUBTEXT int | i2c_writeData (i2c *bus, const unsigned char *data, int count) |
Send a block of i2c data. Does not set start or stop. More... | |
HUBTEXT int | i2c_readData (i2c *bus, unsigned char *data, int count) |
Receive a block of i2c data. Does not send start or stop conditions. More... | |
HUBTEXT int | i2c_poll (i2c *bus, int devaddr) |
Send i2c start and addr byte. Looks for ACK (0) or NACK (1). This is useful for checking if a device is responding or starting a new i2c packet. No stop is sent. More... | |
Provides simple i2c start, stop, send, and receive functions
Copyright (c) 2013, Parallax Inc.
Open an i2c device.
[in] | *bus | is a pointer to an i2c storage variable. |
sclPin | is the number of the Propeller I/O pin connected to the I2C bus' SCL line. | |
sdaPin | is the number of the Propeller I/O pin connected to the I2C bus' SDA line. | |
sclDrive | says drive SCL (1) or not (0). No SCL drive is by far the most common arrangement. Some Propeller boards do not apply a pull- up resistor to the EEPROM's SCL line, and driving the SCL pin is useful in for communicating with EEPROMs on those particular boards. |
HUBTEXT int i2c_poll | ( | i2c * | bus, |
int | addr | ||
) |
Send i2c start and addr byte. Looks for ACK (0) or NACK (1). This is useful for checking if a device is responding or starting a new i2c packet. No stop is sent.
*bus | is the bus pointer returned by i2c_open. |
addr | is the I2C device address. |
HUBTEXT int i2c_readByte | ( | i2c * | bus, |
int | ackState | ||
) |
Receive i2c byte and reply with ack state. Does not set start or stop. Drives SCL line if i2c device opened using sclDrive = 1.
*bus | is the bus pointer returned by i2c_open. |
ackState | sets or clears the acknowledge bit that follows the data byte in I2C. Acknowledge is ACK = 0, and no-acknowledge (NACK = 1). |
HUBTEXT int i2c_readData | ( | i2c * | bus, |
unsigned char * | data, | ||
int | count | ||
) |
Receive a block of i2c data. Does not send start or stop conditions.
The Propeller replies with ACK after each byte received. After the last byte, it replies with NACK to tell the I2C device that it's done receiving bytes.
Drive scl if i2c device opened using sclDrive.
*bus | is the bus pointer returned by i2c_open. |
data | is a pointer to an array of unsigned char bytes. |
count | is the number of bytes to receive. |
HUBTEXT void i2c_start | ( | i2c * | bus) |
Signal i2c start condition on bus.
*bus | is the bus pointer returned by i2c_open. |
HUBTEXT void i2c_stop | ( | i2c * | bus) |
Send Signal i2c stop condition on bus.
*bus | is the bus pointer returned by i2c_open. |
HUBTEXT int i2c_writeByte | ( | i2c * | bus, |
int | byte | ||
) |
Send i2c byte and return acknowledgement from device. Does not set start or stop. Drives SCL line if i2c device opened using sclDrive = 1.
*bus | is the bus pointer returned by i2c_open. |
byte | is the data byte the Propeller chip sends to the I2C device. |
HUBTEXT int i2c_writeData | ( | i2c * | bus, |
const unsigned char * | data, | ||
int | count | ||
) |
Send a block of i2c data. Does not set start or stop.
If the device replies with NACK after receiving a particular data byte, the transmit will terminate. Drive scl if i2c device opened using sclDrive.
*bus | is the bus pointer returned by i2c_open. |
*data | is a pointer to the array of data to send. |
count | is the number of bytes to send. |