PropWare
2.1.2
C++ objects and CMake build system for Parallax Propeller
|
Click here for docs on the
develop
branch.
#include <i2c.h>
Public Member Functions | |
void | Init (const int scl=28, const int sda=29, const int frequency=400000) |
bool | Ping (const unsigned char device) |
bool | Put (const unsigned char device, const unsigned char address, const char byte) |
unsigned char | Get (const unsigned char device, const unsigned char address) |
bool | Put (const unsigned char device, const unsigned char address, const char *bytes, const int size) |
bool | Get (const unsigned char device, const unsigned char address, char *bytes, const int size) |
bool | Put (const unsigned char device, const char byte) |
bool | Get (const unsigned char device, char *bytes, const int size) |
void | Start () |
void | Stop () |
int | SendByte (const unsigned char byte) |
unsigned char | ReadByte (const int acknowledge) |
Public Attributes | |
libpropeller::I2CBase | base_ |
A basic I2C driver.
All "device" fields should be the 7 bit address of the device, with the low bit set to 0 (the 7 addres bits are the upper bits). This applies to both the Put (write) and Get (read) cases.
Put and Get are based on I2C communication specification as described by ST in the LSM303DLHC and L3GD20 datasheets. Terms:
I2C differs based on the device that you use. For functions that might be device specific, there is a reference indicator. These references are:
If you're using the multibyte Get and Put with ST based devices, be sure to bitwise OR the register address with 0x80 (the MSb to 1) in order to turn on the auto-increment function (see datasheet for L3GD20 for example). This is not done automatically by this library.
unsigned char libpropeller::I2C::Get | ( | const unsigned char | device, |
const unsigned char | address | ||
) |
Get a single byte with the following format:
+-----—+-—+----—+--—+--—+--—+-—+----—+--—+---—+---—+-—+ | Master | ST | SAD+W | | SUB | | ST | SAD+R | | | NMAK | SP | | Slave | | | SAK | | SAK | | | SAK | DATA | | | +-----—+-—+----—+--—+--—+--—+-—+----—+--—+---—+---—+-—+
Reference: ST
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0) |
address | the 8 bit slave register address |
Definition at line 111 of file i2c.h.
bool libpropeller::I2C::Get | ( | const unsigned char | device, |
const unsigned char | address, | ||
char * | bytes, | ||
const int | size | ||
) |
Get multiple bytes with the following format:
|Repeat for # of bytes -1 | Last byte |
+-----—+-—+----—+--—+--—+--—+-—+----—+--—+---—+--—+---—+--—+---—+---—+-—+ | Master | ST | SAD+W | | SUB | | ST | SAD+R | | | MAK | | MAK | | NMAK | SP | | Slave | | | SAK | | SAK | | | SAK | DATA | | DATA | | DATA | | | +-----—+-—+----—+--—+--—+--—+-—+----—+--—+---—+--—+---—+--—+---—+---—+-—+
Reference: ST
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0). |
address | the 8 bit slave register address. |
bytes | the address to begin storing the read bytes at. |
size | the number of bytes to read. |
Definition at line 174 of file i2c.h.
bool libpropeller::I2C::Get | ( | const unsigned char | device, |
char * | bytes, | ||
const int | size | ||
) |
Get multiple bytes, no register address, on the bus with the following format:
|Repeat |
+-----—+-—+----—+--—+---—+--—+---—+---—+-—+ | Master | ST | SAD+R | | | MAK | | NMAK | SP | | Slave | | | SAK | DATA | | DATA | | | +-----—+-—+----—+--—+---—+--—+---—+---—+-—+
Reference: MS
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0) |
bytes | the address to begin storing the read bytes at. |
size | the number of bytes to read. |
Definition at line 240 of file i2c.h.
void libpropeller::I2C::Init | ( | const int | scl = 28 , |
const int | sda = 29 , |
||
const int | frequency = 400000 |
||
) |
Setup the DIRA, OUTA, and INA registers for scl and sda.
scl | The I2C SCL pin. Defaults to the Propeller default SCL pin. |
sda | The I2C SDA pin. Defaults to the Propeller default SDA pin. |
frequency | The frequency in hz to run the bus at. |
Definition at line 49 of file i2c.h.
bool libpropeller::I2C::Ping | ( | const unsigned char | device | ) |
Test for the Acknowledge of a device by sending start and the slave address.
Useful for polling the bus and seeing what devices are available. Ping uses the following format:
+-----—+-—+----—+--—+-—+ | Master | ST | SAD+W | | SP | | Slave | | | SAK | | +-----—+-—+----—+--—+-—+
Definition at line 64 of file i2c.h.
bool libpropeller::I2C::Put | ( | const unsigned char | device, |
const unsigned char | address, | ||
const char | byte | ||
) |
Put a single byte with the following format:
+-----—+-—+----—+--—+--—+--—+---—+--—+-—+ | Master | ST | SAD+W | | SUB | | BYTE | | SP | | Slave | | | SAK | | SAK | | SAK | | +-----—+-—+----—+--—+--—+--—+---—+--—+-—+
Reference: ST
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0) |
address | the 8 bit slave register address |
byte | the 8 bits of data to store at address. |
Definition at line 85 of file i2c.h.
bool libpropeller::I2C::Put | ( | const unsigned char | device, |
const unsigned char | address, | ||
const char * | bytes, | ||
const int | size | ||
) |
Put multiple bytes with the following format:
|Repeat for # of bytes |
+-----—+-—+----—+--—+--—+--—+---—+--—+---—+--—+-—+ | Master | ST | SAD+W | | SUB | | DATA | | DATA | | SP | | Slave | | | SAK | | SAK | | SAK | | SAK | | +-----—+-—+----—+--—+--—+--—+---—+--—+---—+--—+-—+
Reference: ST
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0) |
address | the 8 bit slave register address |
bytes | the set of bytes to store on device, starting at register address. |
size | the number of bytes to write |
Definition at line 142 of file i2c.h.
bool libpropeller::I2C::Put | ( | const unsigned char | device, |
const char | byte | ||
) |
Put a single byte, no register address, on the bus with the following format :
+-----—+-—+----—+--—+---—+--—+-—+ | Master | ST | SAD+W | | DATA | | SP | | Slave | | | SAK | | SAK | | +-----—+-—+----—+--—+---—+--—+-—+
Reference: MS
device | the 7 bit slave I2C address (in bits 7-1, with bit 0 set to 0) |
byte | the 8 bits of data to send to device |
Definition at line 209 of file i2c.h.
unsigned char libpropeller::I2C::ReadByte | ( | const int | acknowledge | ) |
int libpropeller::I2C::SendByte | ( | const unsigned char | byte | ) |
void libpropeller::I2C::Start | ( | ) |
void libpropeller::I2C::Stop | ( | void | ) |