#include <i2c_base.hpp>

Inheritance diagram for I2C_Base:

Public Member Functions

void handleInterrupt ()
 
uint8_t readReg (uint8_t deviceAddress, uint8_t registerAddress)
 
bool writeReg (uint8_t deviceAddress, uint8_t registerAddress, uint8_t value)
 
bool readRegisters (uint8_t deviceAddress, uint8_t firstReg, uint8_t *pData, uint32_t transferSize)
 
bool writeRegisters (uint8_t deviceAddress, uint8_t firstReg, uint8_t *pData, uint32_t transferSize)
 
bool checkDeviceResponse (uint8_t deviceAddress)
 

Protected Member Functions

 I2C_Base (LPC_I2C_TypeDef *pI2CBaseAddr)
 
bool init (uint32_t pclk, uint32_t busRateInKhz)
 
void disableOperation ()
 

Detailed Description

I2C Base class that can be used to write drivers for all I2C peripherals. Steps needed to write a I2C driver:

  • Inherit this class
  • Call init() and configure PINSEL to select your I2C pins
  • When your I2C(#) hardware interrupt occurs, call handleInterrupt()

To connect I2C Interrupt with your I2C, reference this example:

extern "C"
{
{
I2C0::getInstance().handleInterrupt();
}
}

Constructor & Destructor Documentation

I2C_Base::I2C_Base ( LPC_I2C_TypeDef pI2CBaseAddr)
protected

Protected constructor that requires parent class to provide I2C base register address for which to operate this I2C driver

Member Function Documentation

bool I2C_Base::checkDeviceResponse ( uint8_t  deviceAddress)

This function can be used to check if an I2C device responds to its address, which can therefore be used to discover all I2C hardware devices. Sometimes this method is used by devices to check if they are ready for further operations such as an EEPROM or FLASH memory.

Parameters
deviceAddressThe device address to check for I2C response
Returns
true if I2C device with given address is ready
void I2C_Base::disableOperation ( )
inlineprotected

Disables I2C operation This can be used to disable all I2C operations in case of severe I2C Bus Failure

Warning
Once disabled, I2C cannot be enabled again
void I2C_Base::handleInterrupt ( )

When the I2C interrupt occurs, this function should be called to handle future action to take due to the interrupt cause.

bool I2C_Base::init ( uint32_t  pclk,
uint32_t  busRateInKhz 
)
protected

Initializes I2C Communication BUS

Parameters
pclkThe peripheral clock to the I2C Bus
busRateInKhzThe speed to set for this I2C Bus

Per I2C high speed mode: HS mode master devices generate a serial clock signal with a HIGH to LOW ratio of 1 to 2. So to be able to optimize speed, we use different duty cycle for high/low

Compute the I2C clock dividers. The LOW period can be longer than the HIGH period because the rise time of SDA/SCL is an RC curve, whereas the fall time is a sharper curve.

uint8_t I2C_Base::readReg ( uint8_t  deviceAddress,
uint8_t  registerAddress 
)

Reads a single byte from an I2C Slave

Parameters
deviceAddressThe I2C Device Address
registerAddressThe register address to read
Returns
The byte read from slave device (might be 0 if error)
bool I2C_Base::readRegisters ( uint8_t  deviceAddress,
uint8_t  firstReg,
uint8_t *  pData,
uint32_t  transferSize 
)

bool I2C_Base::writeReg ( uint8_t  deviceAddress,
uint8_t  registerAddress,
uint8_t  value 
)

Writes a single byte to an I2C Slave

Parameters
deviceAddressThe I2C Device Address
registerAddressThe register address to write
valueThe value to write to registerAddress
Returns
true if successful
bool I2C_Base::writeRegisters ( uint8_t  deviceAddress,
uint8_t  firstReg,
uint8_t *  pData,
uint32_t  transferSize 
)


The documentation for this class was generated from the following files:
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L2_Drivers/base/i2c_base.hpp
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L2_Drivers/base/i2c_base.cpp