 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		| 
//CONFIGURE REGISTER PORTION
uint8 configOctalRegister(void)
{
uint8 stat;
uint8 buff[2] = { 0x03, 0x7F }; // 0x03 = CONIG REGISTER, 0x7F = pins 1 - 6 are inputs and pin 7 is an output
stat = writeI2C( ADDR_1, 2, buff, 1 ); //octalRegister1
return stat;
}
 | 
| 
int writeI2C(uint8 addr, uint8 sz, uint8 *buff, uint8 bus)
{
  uint8 i;
  uint16 stat;
  /* shift address to bits 7-1; bit 0 is R/W */
  I2CMasterBuffer[0] = addr<<1;
  /* write "size" + 1 uint8 for address */
  I2CWrLength = sz + 1;
  I2CRdLength = 0;
  for (i = 0; i < sz; i++)
I2CMasterBuffer[i+1] = buff;
    
  stat = I2CEngine(bus);
  return stat;
} | 
| 
uint8 readExpanderPins( uint8 addr)
{
uint8 stat;
uint8 buff;
        buff = 0x00; //read the input port register
        stat = write_readI2C( ADDR_1, 1, 0x00, &buff, 1 );  //passing the addr, readSize, offset, buffer, bus
if(!stat)
{
bit2status = ( buff & 0x04 ); //buff[2]; bit2
bit3tatus = ( buff & 0x08 ); //buff[3]; bit3
bit4status = ( buff & 0x01 ); //buff[4]; bit4
bit5status = ( buff & 0x20 ); //buff[5]; bit5
bit6status = ( buff & 0x40 ); //buff[6]; bit6
}
return stat;
 | 
| 
int write_readI2C(uint8 addr, uint8 sz, uint8 offset, uint8 *buff, uint8 bus)
{
  uint8 i;
  uint16 stat;
  /* shift address to bits 7-1; bit 0 is R/W */
  I2CMasterBuffer[0] = addr<<1;
  /* write 2 size: I2C address + offset to read */
  I2CWrLength = 2;
  I2CMasterBuffer[1] = offset;
    
  /* now load read command */
  I2CMasterBuffer[2] = addr<<1 | RD_BIT;
  I2CRdLength = sz;
  stat = I2CEngine(bus); 
  if (stat)
    return stat;
  if (RdIndex == 0) //no data was read
return FAIL; //(I2C_ERR_MASK | RD_ERR);
  for ( i = 0; i < sz; i++ )
    buff = I2CMasterBuffer[i+3];
  return stat; 
}
 | 
