simple i2c library  v0.85
Covers I2C basics like start/stop conditions and byte & data send & receive
Functions
simplei2c.c File Reference
#include "simplei2c.h"

Functions

HUBTEXT i2ci2c_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...
 

Detailed Description

Provides simple i2c start, stop, send, and receive functions

Copyright (c) 2013, Parallax Inc.

Function Documentation

HUBTEXT i2c* i2c_open ( i2c bus,
int  sclPin,
int  sdaPin,
int  sclDrive 
)

Open an i2c device.

Parameters
[in]*busis a pointer to an i2c storage variable.
sclPinis the number of the Propeller I/O pin connected to the I2C bus' SCL line.
sdaPinis the number of the Propeller I/O pin connected to the I2C bus' SDA line.
sclDrivesays 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.
Returns
Copy of the bus address.
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.

Parameters
*busis the bus pointer returned by i2c_open.
addris the I2C device address.
Returns
(ACK = 0_ if device has responded.
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.

Parameters
*busis the bus pointer returned by i2c_open.
ackStatesets or clears the acknowledge bit that follows the data byte in I2C. Acknowledge is ACK = 0, and no-acknowledge (NACK = 1).
Returns
The byte Propeller chip reads from I2C device.
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.

Parameters
*busis the bus pointer returned by i2c_open.
datais a pointer to an array of unsigned char bytes.
countis the number of bytes to receive.
Returns
the number of bytes sent.
HUBTEXT void i2c_start ( i2c bus)

Signal i2c start condition on bus.

Parameters
*busis the bus pointer returned by i2c_open.
HUBTEXT void i2c_stop ( i2c bus)

Send Signal i2c stop condition on bus.

Parameters
*busis 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.

Parameters
*busis the bus pointer returned by i2c_open.
byteis the data byte the Propeller chip sends to the I2C device.
Returns
Acknowledge bit value (ACK = 0) or no-acknowledge (NACK = 1) from receiving 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.

Parameters
*busis the bus pointer returned by i2c_open.
*datais a pointer to the array of data to send.
countis the number of bytes to send.
Returns
the number of bytes sent (including address byte).