Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
Joseph Ryan edited this page Aug 19, 2017 · 11 revisions

Go to the source code for i2c.h

Includes

  • #include "common.h"
  • #include "gpio.h"

Functions

Function Documention


InitializeI2C

Initializes an I2C module on a pair of pins

tI2C *InitializeI2C(tPin sda, tPin scl);

Parameters:

  • sda [TODO: describe sda]
  • scl [TODO: describe scl]

Returns:

  • Pointer to a I2C module used by other i2c functions

I2CSuccess

Checks if the previous i2c transaction was successful

tBoolean I2CSuccess(tI2C *i2c);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C

Returns:

  • true if the previous i2c transaction was successful

I2CBackgroundSend

Sends data to an I2C address

void I2CBackgroundSend(tI2C *i2c, unsigned char addr, const unsigned char *data, unsigned int len, tCallback callback, void *cbdata);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being sent
  • data Pointer to array of byes being sent
  • len Number of bytes in data array
  • callback Function that will be called when the data has been sent
  • cbdata Argument sent to the callback whenever it is called

I2CSend

Sends data to an I2C address

tBoolean I2CSend(tI2C *i2c, unsigned char addr, const unsigned char *data, unsigned int len);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being sent
  • data Pointer to array of byes being sent
  • len Number of bytes in data array

Returns:

  • true if successful

I2CBackgroundReceive

Receives data from an I2C address

void I2CBackgroundReceive(tI2C *i2c, unsigned char addr, unsigned char *data, unsigned int len, tCallback callback, void *cbdata);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being received
  • data Pointer to array of byes to store the data received
  • len Number of bytes allocated in the data array
  • callback Function that will be called when all of the data is received
  • cbdata Argument sent to the callback whenever it is called

I2CReceive

Receives data from an I2C address

tBoolean I2CReceive(tI2C *i2c, unsigned char addr, unsigned char* data, unsigned int len);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being received
  • data Pointer to array of byes to store the data received
  • len Number of bytes allocated in the data array

Returns:

  • true if successful

I2CBackgroundRequest

Requests data from an I2C address (nonblocking). This is the same as two sequential send and recieve calls but takes place in the internal state machine.

void I2CBackgroundRequest(tI2C *i2c, unsigned char addr, const unsigned char *sendData, unsigned int sendLen, unsigned char *recData, unsigned int recLen, tCallback callback, void *cbdata);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being requested
  • sendData Pointer to array of byes being sent
  • sendLen Number of bytes allocated in the send data array
  • recData Pointer to array of byes to store the data received
  • recLen Number of bytes allocated in the receive data array
  • callback Function that will be called when all of the data is received
  • cbdata Argument sent to the callback whenever it is called

I2CRequest

Requests data from an I2C address (blocking). This is the same as two sequential send and recieve calls but takes place in the internal state machine.

tBoolean I2CRequest(tI2C *i2c, unsigned char addr, const unsigned char *sendData, unsigned int sendLen, unsigned char *recData, unsigned int recLen);

Parameters:

  • i2c An initialized I2C module, which is returned by InitializeI2C
  • addr I2C address where data is being requested
  • sendData Pointer to array of byes being sent
  • sendLen Number of bytes allocated in the send data array
  • recData Pointer to array of byes to store the data received
  • recLen Number of bytes allocated in the receive data array

Returns:

  • true if successful