libpropeller
Making PropellerGCC Easier
|
#include <i2c.h>
Public Member Functions | |
void | Init (const int scl=28, const int sda=29, const int frequency=400000) |
Setup the DIRA, OUTA, and INA registers for scl and sda. More... | |
bool | Ping (const unsigned char device) |
Test for the Acknowledge of a device by sending start and the slave address. More... | |
bool | Put (const unsigned char device, const unsigned char address, const char byte) |
Put a single byte with the following format: More... | |
unsigned char | Get (const unsigned char device, const unsigned char address) |
Get a single byte with the following format: More... | |
bool | Put (const unsigned char device, const unsigned char address, const char *bytes, const int size) |
Put multiple bytes with the following format: More... | |
bool | Get (const unsigned char device, const unsigned char address, char *bytes, const int size) |
Get multiple bytes with the following format: More... | |
bool | Put (const unsigned char device, const char byte) |
Put a single byte, no register address, on the bus with the following format : More... | |
bool | Get (const unsigned char device, char *bytes, const int size) |
Get multiple bytes, no register address, on the bus with the following format: More... | |
void | Start () |
Passthrough to base. More... | |
void | Stop () |
Passthrough to base. More... | |
int | SendByte (const unsigned char byte) |
Passthrough to base. More... | |
unsigned char | ReadByte (const int acknowledge) |
Passthrough to base. More... | |
Public Attributes | |
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.
|
inline |
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 |
|
inline |
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. |
|
inline |
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. |
|
inline |
|
inline |
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 | | +-----—+-—+----—+--—+-—+
|
inline |
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. |
|
inline |
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 |
|
inline |
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 |
|
inline |
Passthrough to base.
See i2cBase::ReadByte(int) for more details.
|
inline |
Passthrough to base.
See i2cBase::SendByte(unsigned char) for more details.
|
inline |
Passthrough to base.
See i2cBase::Start() for more details.
|
inline |
Passthrough to base.
See i2cBase::Stop() for more details.
I2CBase I2C::base_ |