Provides simple i2c start, stop, read, and write functions. See simpletools library for additional I2C functions.
More...
#include <propeller.h>
Go to the source code of this file.
|
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 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. More...
|
|
Provides simple i2c start, stop, read, and write functions. See simpletools library for additional I2C functions.
- Version
- 0.85
- Copyright
- Copyright (c) 2013, Parallax Inc. All Rights MIT Licensed.
Copyright (c) 2013, Parallax Inc.
HUBTEXT i2c* i2c_open |
( |
i2c * |
bus, |
|
|
int |
sclPin, |
|
|
int |
sdaPin, |
|
|
int |
sclDrive |
|
) |
| |
Open an i2c device.
- Parameters
-
[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. |
- 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
-
*bus | is the bus pointer returned by i2c_open. |
addr | is 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
-
*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). |
- 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
-
*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. |
- Returns
- the number of bytes sent.
HUBTEXT void i2c_start |
( |
i2c * |
bus) | |
|
Signal i2c start condition on bus.
- Parameters
-
*bus | is the bus pointer returned by i2c_open. |
HUBTEXT void i2c_stop |
( |
i2c * |
bus) | |
|
Send Signal i2c stop condition on bus.
- Parameters
-
*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.
- Parameters
-
*bus | is the bus pointer returned by i2c_open. |
byte | is 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
-
*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. |
- Returns
- the number of bytes sent (including address byte).