myWRIO
C++ framework for NationalInstruments myRIO
myRIO::I2C Class Reference

In this configuration, myRIO will always be the master. More...

#include <I2C.h>

Public Member Functions

void close ()
 Delete (somehow violently) an I2C object. More...
 
I2Cslave (uint8_t addr)
 Set the slave address to talk to. More...
 
bool write (uint8_t reg, uint8_t data)
 Write 8 bits data to the given registry on a previously set slave. More...
 
bool writeFrom (uint8_t reg, uint8_t *data, uint8_t dataSize)
 Write any size of data starting from reg address. More...
 
bool read (uint8_t reg, uint8_t *data)
 Read a register and get that data back to data. More...
 
bool readFrom (uint8_t reg, uint8_t *data, uint8_t dataSize)
 Read multiple registers, starting to reg. More...
 
I2C speed (int SPD_XXKBPS)
 Set the I2C bus speed. More...
 
bool start (bool RW, uint8_t reg, uint8_t *data, uint8_t dataSize)
 Begin the procedure. More...
 
 ~I2C ()
 Close the I2C channel. More...
 

Static Public Member Functions

static I2Copen ()
 You can use this to open multiple I2C channels, for exemple use I2CB. More...
 

Private Member Functions

 I2C ()
 Enable the I2C channel A on myRIO. More...
 
uint8_t wait ()
 Wait for myRIO to end a frame. More...
 
bool checkErrors (uint8_t state)
 Check for errors during the previous communication. More...
 

Private Attributes

uint8_t slaveAddr
 Slave address. More...
 
uint8_t cntr
 Contains informations relative to the procedure to come. More...
 

Static Private Attributes

static int nbInstance = 0
 

Detailed Description

In this configuration, myRIO will always be the master.

Definition at line 41 of file I2C.h.

Constructor & Destructor Documentation

◆ ~I2C()

I2C::~I2C ( )

Close the I2C channel.

Definition at line 245 of file I2C.cpp.

◆ I2C()

I2C::I2C ( )
private

Enable the I2C channel A on myRIO.

Definition at line 10 of file I2C.cpp.

Member Function Documentation

◆ checkErrors()

bool I2C::checkErrors ( uint8_t  state)
private

Check for errors during the previous communication.

Stop the communication if there was one.

Parameters
statethe state of the previous communication,
See also
I2C::wait
Returns
true if there was no error

Definition at line 224 of file I2C.cpp.

◆ close()

void I2C::close ( )

Delete (somehow violently) an I2C object.

Definition at line 238 of file I2C.cpp.

◆ open()

I2C * I2C::open ( )
static

You can use this to open multiple I2C channels, for exemple use I2CB.

Definition at line 30 of file I2C.cpp.

◆ read()

bool I2C::read ( uint8_t  reg,
uint8_t *  data 
)

Read a register and get that data back to data.

Parameters
regthe register to read
dataplace to save the read data

Definition at line 70 of file I2C.cpp.

◆ readFrom()

bool I2C::readFrom ( uint8_t  reg,
uint8_t *  data,
uint8_t  dataSize 
)

Read multiple registers, starting to reg.

Parameters
regthe register to start from
datathe place to save the data. Make sure that it is already allocated.
dataSizethe number of registers to read

Definition at line 80 of file I2C.cpp.

◆ slave()

I2C * I2C::slave ( uint8_t  addr)

Set the slave address to talk to.

Parameters
addrthe slave address on 7 bits, starting from the MSB.

Definition at line 41 of file I2C.cpp.

◆ speed()

I2C I2C::speed ( int  spd)

Set the I2C bus speed.

Parameters
spdone of SPD_100KBPS, SPD_400KBPS or any value in kbps (for 150kbps, spd = 150)

Definition at line 90 of file I2C.cpp.

◆ start()

bool I2C::start ( bool  RW,
uint8_t  reg,
uint8_t *  data,
uint8_t  dataSize 
)

Begin the procedure.

Read the source code documentation to understand what's going on.

Parameters
RWone of WRITE (0) or READ (1)
regthe concerned register
datathe data to read or write
dataSizethe ammount of data to read or write

Definition at line 102 of file I2C.cpp.

◆ wait()

uint8_t I2C::wait ( )
private

Wait for myRIO to end a frame.

Returns
the state of the communication, giving informations about possible errors

Definition at line 210 of file I2C.cpp.

◆ write()

bool I2C::write ( uint8_t  reg,
uint8_t  data 
)

Write 8 bits data to the given registry on a previously set slave.

Parameters
regthe register address on the slave
datathe data to send

Definition at line 51 of file I2C.cpp.

◆ writeFrom()

bool I2C::writeFrom ( uint8_t  reg,
uint8_t *  data,
uint8_t  dataSize 
)

Write any size of data starting from reg address.

Parameters
regthe register address on the slave
datathe data to send
dataSizethe size of the data to send

Definition at line 61 of file I2C.cpp.

Member Data Documentation

◆ cntr

uint8_t myRIO::I2C::cntr
private

Contains informations relative to the procedure to come.

Definition at line 62 of file I2C.h.

◆ nbInstance

int I2C::nbInstance = 0
staticprivate

Definition at line 55 of file I2C.h.

◆ slaveAddr

uint8_t myRIO::I2C::slaveAddr
private

Slave address.

Definition at line 61 of file I2C.h.


The documentation for this class was generated from the following files: