PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Classes | Typedefs | Functions
simplei2c.h File Reference

Provides simple i2c start, stop, read, and write functions. See simpletools library for additional I2C functions. More...

#include <propeller.h>
+ Include dependency graph for simplei2c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  i2c_st
 

Typedefs

typedef struct i2c_st i2c
 

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

Detailed Description

Provides simple i2c start, stop, read, and write functions. See simpletools library for additional I2C functions.

Version
0.85

Copyright (c) 2013, Parallax Inc.

Definition in file simplei2c.h.


Class Documentation

◆ i2c_st

struct i2c_st

Definition at line 25 of file simplei2c.h.

+ Collaboration diagram for i2c_st:
Class Members
int drivescl
volatile int scl_mask
volatile int scl_mask_inv
int sda_mask
int sda_mask_inv

Function Documentation

◆ i2c_open()

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.

Definition at line 60 of file simplei2c.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i2c_poll()

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.

Definition at line 227 of file simplei2c.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i2c_readByte()

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.

Definition at line 175 of file simplei2c.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i2c_readData()

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.

Definition at line 216 of file simplei2c.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i2c_start()

HUBTEXT void i2c_start ( i2c bus)

Signal i2c start condition on bus.

Parameters
*busis the bus pointer returned by i2c_open.

Definition at line 71 of file simplei2c.c.

+ Here is the caller graph for this function:

◆ i2c_stop()

HUBTEXT void i2c_stop ( i2c bus)

Send Signal i2c stop condition on bus.

Parameters
*busis the bus pointer returned by i2c_open.

Definition at line 78 of file simplei2c.c.

+ Here is the caller graph for this function:

◆ i2c_writeByte()

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.

Definition at line 151 of file simplei2c.c.

+ Here is the caller graph for this function:

◆ i2c_writeData()

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).

Definition at line 203 of file simplei2c.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: