Example #1
0
error_t mpl115a2ReadPressureTemp(uint16_t *pressure, uint16_t *temp)
{
  I2CWriteLength = 3;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_STARTCONVERSION;
  I2CMasterBuffer[2] = 0x00;  // Why is this necessary to get results?
  i2cEngine();

  /* Wait a bit for the conversion to complete (3ms max) */
  delay(4);

  I2CWriteLength = 2;
  I2CReadLength = 4;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_PRESSURE_MSB;
  I2CMasterBuffer[2] = MPL115A2_ADDRESS | MPL115A2_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  /* Shift values to create properly formed integers */
  *pressure = ((I2CSlaveBuffer[0] << 8) | (I2CSlaveBuffer[1])) >> 6;
  *temp = ((I2CSlaveBuffer[2] << 8) | (I2CSlaveBuffer[3])) >> 6;

  return ERROR_NONE;
}
Example #2
0
mpl115a2Error_t mpl115a2ReadPressureTemp(uint16_t *pressure, uint16_t *temp)
{
  // Clear write buffers
  uint32_t i;
  for ( i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
    I2CSlaveBuffer[i] = 0x00;
  }

  I2CWriteLength = 3;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_STARTCONVERSION;
  I2CMasterBuffer[2] = 0x00;  // Why is this necessary to get results?
  i2cEngine();

  // Wait a bit for the conversion to complete (3ms max)
  systickDelay(5);

  I2CWriteLength = 2;
  I2CReadLength = 4;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_PRESSURE_MSB;
  I2CMasterBuffer[2] = MPL115A2_ADDRESS | MPL115A2_READBIT;
  i2cEngine();

  // Shift values to create properly formed integers
  *pressure = ((I2CSlaveBuffer[0] << 8) | (I2CSlaveBuffer[1])) >> 6;
  *temp = ((I2CSlaveBuffer[2] << 8) | (I2CSlaveBuffer[3])) >> 6;

  return MPL115A2_ERROR_OK;
}
error_t pca9685ReadBytes(uint8_t reg, uint8_t *buffer, size_t length)
{
  uint32_t i;

  /* Try to avoid buffer overflow */
  ASSERT(length <= I2C_BUFSIZE, ERROR_BUFFEROVERFLOW);

  /* Read and write need to be handled in separate transactions or the
     PCA9685 increments the current register one step ahead of where
     we should be. */

  /* Write transaction */
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = _pca9685Address;
  I2CMasterBuffer[1] = reg;
  i2cEngine();

  /* Read transaction */
  I2CWriteLength = 0;
  I2CReadLength = length;
  I2CMasterBuffer[0] = _pca9685Address | PCA9685_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  /* Fill the buffer with the I2C response */
  for ( i = 0; i < length; i++ )
  {
    buffer[i] = I2CSlaveBuffer[i];
  }

  return ERROR_NONE;
}
Example #4
0
static uint8_t lkGetI2C(uint8_t cr) {
    I2CMasterBuffer[0] = LK_I2C_WRITE;
    I2CMasterBuffer[1] = cr;
    I2CWriteLength = 2;
    I2CReadLength = 0;
    i2cEngine();

    I2CMasterBuffer[0] = LK_I2C_READ;
    I2CMasterBuffer[1] = cr;
    I2CWriteLength = 2;
    I2CReadLength = 1;
    i2cEngine();
    return I2CSlaveBuffer[0];
}
Example #5
0
static uint32_t adxl345ReadMultiByte(uint8_t address, uint8_t reg, uint8_t numBytes, uint8_t value[])
{
  // Clear write buffers
  uint32_t i;
  for (i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
  }

  I2CWriteLength = 0;
  I2CReadLength = numBytes;
  I2CMasterBuffer[0] = address;             // I2C device address
  I2CMasterBuffer[1] = reg;                       // Command register
  // Append address w/read bit
  I2CMasterBuffer[2] = address | adxl345_READBIT;
  uint32_t returned = i2cEngine();
  if(returned == i2c_ok)
  {
	  int i;
	  for(i = 0; i < numBytes; i++)
	  {
		  value[i] = I2CSlaveBuffer[i];
	  }
  }

  return returned;
}
Example #6
0
mpl115a2Error_t mpl115a2ReadCoefficients(void)
{
  int16_t a0coeff;
  int16_t b1coeff;
  int16_t b2coeff;
  int16_t c12coeff;

  // Clear write buffers
  uint32_t i;
  for ( i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
    I2CSlaveBuffer[i] = 0x00;
  }

  I2CWriteLength = 2;
  I2CReadLength = 8;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_A0_COEFF_MSB;
  I2CMasterBuffer[2] = MPL115A2_ADDRESS | MPL115A2_READBIT;  
  i2cEngine();

  a0coeff = (I2CSlaveBuffer[0] << 8 ) | I2CSlaveBuffer[1];
  b1coeff = (I2CSlaveBuffer[2] << 8 ) | I2CSlaveBuffer[3];
  b2coeff = (I2CSlaveBuffer[4] << 8 ) | I2CSlaveBuffer[5];
  c12coeff = ((I2CSlaveBuffer[6] << 8 ) | I2CSlaveBuffer[7]) >> 2; 

  _mpl115a2_a0 = (float)a0coeff / 8;
  _mpl115a2_b1 = (float)b1coeff / 8192;
  _mpl115a2_b2 = (float)b2coeff / 16384;
  _mpl115a2_c12 = (float)c12coeff / 4194304;

  return MPL115A2_ERROR_OK;
}
Example #7
0
error_t mpl115a2ReadCoefficients(void)
{
  int16_t a0coeff;
  int16_t b1coeff;
  int16_t b2coeff;
  int16_t c12coeff;

  I2CWriteLength = 2;
  I2CReadLength = 8;
  I2CMasterBuffer[0] = MPL115A2_ADDRESS;
  I2CMasterBuffer[1] = MPL115A2_REGISTER_A0_COEFF_MSB;
  I2CMasterBuffer[2] = MPL115A2_ADDRESS | MPL115A2_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  a0coeff = (I2CSlaveBuffer[0] << 8 ) | I2CSlaveBuffer[1];
  b1coeff = (I2CSlaveBuffer[2] << 8 ) | I2CSlaveBuffer[3];
  b2coeff = (I2CSlaveBuffer[4] << 8 ) | I2CSlaveBuffer[5];
  c12coeff = ((I2CSlaveBuffer[6] << 8 ) | I2CSlaveBuffer[7]) >> 2;

  _mpl115a2_a0 = (float)a0coeff / 8;
  _mpl115a2_b1 = (float)b1coeff / 8192;
  _mpl115a2_b2 = (float)b2coeff / 16384;
  _mpl115a2_c12 = (float)c12coeff / 4194304;

  return ERROR_NONE;
}
// Grabs line sensor data using i2c and dumps into LineSensor array. 
// Returns 1 if successful, 0 if encountered a timeout error 
//	(timeout probably means the line sensor isn't connected correctly)
int readLineSensor(char data[])
{
	int i;
	char cmd = 0x84; //1 CH# 01 XX for request conversion. e.g 1 000 01 00 is for channel 2
	
	for(i=0; i<I2C_BUFSIZE; i++)
	{
		I2CWriteLength = 2;
		I2CReadLength = 1;
		I2CMasterBuffer[0] = ADS7830;
		I2CMasterBuffer[1] = cmd; 
		I2CMasterBuffer[2] = ADS7830 | 1;
		
		cmd += 0x10;	// Increment Channel to read
		
		if (i2cEngine() > MAX_TIMEOUT)	// Run I2C sensor
		{	
			return 0;
		}
		data[i] = I2CSlaveBuffer[0]; //sadly after each transaction the RdIndex is returned to 0, could change i2c driver...
	} 
	
	// Clean the buffer after use
	clearI2CBuffer();
	
	return 1;
}
Example #9
0
static i2c_error itg3200ReadMultiByte(uint8_t address, uint8_t reg, uint8_t numBytes, uint8_t value[])
{
    // Clear write buffers
    uint32_t i;
    for (i = 0; i < I2C_BUFSIZE; i++ )
    {
        I2CMasterBuffer[i] = 0x00;
    }

    I2CWriteLength = 0;
    I2CReadLength = numBytes;
    I2CMasterBuffer[0] = address;             // I2C device address
    I2CMasterBuffer[1] = reg;                       // Command register
    // Append address w/read bit
    I2CMasterBuffer[2] = address | itg3200_READBIT;
    i2c_error returned = i2cEngine();
    if(returned == i2c_ok)
    {
        // Shift values to create properly formed integer
        int i;
        for(i = 0; i < numBytes; i++)
        {
            value[i] = I2CSlaveBuffer[i];
        }
    }

    return returned;
}
pn532_error_t pn532_bus_i2c_WriteData (const byte_t * pbtData, const size_t szData)
{
  uint32_t i;
  uint32_t i2cState;

  // Send the specified bytes
  I2CWriteLength = szData+1;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = PN532_I2C_ADDRESS;         // I2C device address
  for ( i = 0; i < szData; i++ )
  {
    I2CMasterBuffer[i+1] = pbtData[i];
  }
  i2cState = i2cEngine();

  // Check if we got an ACK
  if ((i2cState == I2CSTATE_NACK) || (i2cState == I2CSTATE_SLA_NACK))
  {
    // I2C slave didn't acknowledge the master transfer
    // The PN532 probably isn't connected properly or the
    // bus select pins are in the wrong state
    return PN532_ERROR_I2C_NACK;
  }
  if (i2cState == I2CSTATE_TIMEOUT)
  {
        // The most likely cause of this is missing pullups on I2C
        return PN532_ERROR_I2C_TIMEOUT;
  }

  return PN532_ERROR_NONE;
}
// Grabs line sensor data using i2c and dumps into LineSensor array. 
// Returns 1 if successful, 0 if encountered a timeout error 
//	(timeout probably means the line sensor isn't connected correctly)
int readLineSensor(int LineSensor[8]) {
	int i;
	char cmd;

	gpioSetValue(2, 10, 1);
	for(i=0; i<8; i++) //clear i2c buffers
	{
		I2CMasterBuffer[i] = 0;
		I2CSlaveBuffer[i] = 0;
	}

	cmd = 0x84; //1 CH# 01 XX for request conversion. e.g 1 000 01 00 is for channel 2

	for(i=0; i<8; i++)
	{
		////printf("Reading channel %d\n\r", i);
		I2CWriteLength = 2;
		I2CReadLength = 1;
		I2CMasterBuffer[0] = ADS7830_ADDR;
		I2CMasterBuffer[1] = cmd; 
		cmd += 0x10; //increment channel
		I2CMasterBuffer[2] = ADS7830_ADDR | READ_BIT; //not included in writelength b/c its a repeated start
		int timeout = i2cEngine(); //run the transaction and waits for value to be read back
		if (timeout > MAX_TIMEOUT) {
			//printf("ERROR: timeout (device not connected correctly)\n\r");
			return 0;
		}
		LineSensor[i] = I2CSlaveBuffer[0]; //> 100 ? 999 : 0; //sadly after each transaction the RdIndex is returned to 0, could change i2c driver...
	} 

	return 1;
}
Example #12
0
err_t adxl345GetXYZ(int16_t *x, int16_t *y, int16_t *z)
{
  int32_t i2cState;

  if (!_adxl345Initialised)
  {
    ASSERT_STATUS(adxl345Init());
  }

  I2CWriteLength = 2;
  I2CReadLength = 6;
  I2CMasterBuffer[0] = ADXL345_ADDRESS;
  I2CMasterBuffer[1] = ADXL345_REG_DATAX0;
  I2CMasterBuffer[2] = ADXL345_ADDRESS | ADXL345_READBIT;
  i2cState = i2cEngine();

  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cState);

  /* Shift values to create properly formed integer */
  *x = (I2CSlaveBuffer[1] << 8) | (I2CSlaveBuffer[0]);
  *y = (I2CSlaveBuffer[3] << 8) | (I2CSlaveBuffer[2]);
  *z = (I2CSlaveBuffer[5] << 8) | (I2CSlaveBuffer[4]);

  return ERROR_NONE;
}
Example #13
0
static uint32_t adxl345ReadByte(uint8_t address, uint8_t reg, int *value)
{
  // Clear write buffers
  uint32_t i;
  for (i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
  }

  I2CSlaveBuffer[0] = 0x00;

  I2CWriteLength = 0;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = address;             // I2C device address
  I2CMasterBuffer[1] = reg;                       // Command register
  // Append address w/read bit
  I2CMasterBuffer[2] = address | adxl345_READBIT;
  uint32_t returned = i2cEngine();
  if(returned == i2c_ok)
  {
	  // Shift values to create properly formed integer
	  *value = I2CSlaveBuffer[0];
  }

  return returned;
}
isl12022mError_t isl12022mReadBuffer(uint8_t address, uint8_t reg, uint8_t *buffer, uint32_t len)
{
  if (len > I2C_BUFSIZE)
    return ISL12022M_ERROR_I2C_BUFFEROVERFLOW;

  // Clear write buffers
  uint32_t i;
  for ( i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
  }

  I2CWriteLength = 2;
  I2CReadLength = len;
  I2CMasterBuffer[0] = address;
  I2CMasterBuffer[1] = reg;                       // Command register
  // Append address w/read bit
  I2CMasterBuffer[2] = address | ISL12022M_READBIT;  
  i2cEngine();

  // Push response into buffer
  for ( i = 0; i < len; i++ )
  {
    buffer[i] = I2CSlaveBuffer[i];
  }

  return ISL12022M_ERROR_OK;
}
Example #15
0
static uint32_t lkSetI2C(uint8_t cr, uint8_t value) {
    I2CMasterBuffer[0] = LK_I2C_WRITE;
    I2CMasterBuffer[1] = cr;
    I2CMasterBuffer[2] = value;
    I2CWriteLength = 3;
    I2CReadLength = 0;
    return i2cEngine();
}
Example #16
0
error_t tcs34725Read8(uint8_t reg, uint8_t *value)
{
  /* Write transaction */
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TCS34725_ADDRESS;
  I2CMasterBuffer[1] = TCS34725_COMMAND_BIT | reg;
  i2cEngine();

  /* Read transaction */
  I2CWriteLength = 0;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = TCS34725_ADDRESS | TCS34725_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  *value = I2CSlaveBuffer[0];

  return ERROR_NONE;
}
Example #17
0
err_t tsl2561WriteCmd (uint8_t cmd)
{
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TSL2561_ADDRESS;
  I2CMasterBuffer[1] = cmd;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
Example #18
0
error_t tcs34725Read16(uint8_t reg, uint16_t *value)
{
  /* Write transaction */
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TCS34725_ADDRESS;
  I2CMasterBuffer[1] = TCS34725_COMMAND_BIT | reg;
  i2cEngine();

  /* Read transaction */
  I2CWriteLength = 0;
  I2CReadLength = 2;
  I2CMasterBuffer[0] = TCS34725_ADDRESS | TCS34725_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  /* Shift values to create properly formed integer (low byte first) */
  *value = (I2CSlaveBuffer[0] | (I2CSlaveBuffer[1] << 8));

  return ERROR_NONE;
}
Example #19
0
error_t tcs34725Write8 (uint8_t reg, uint8_t value)
{
  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TCS34725_ADDRESS;
  I2CMasterBuffer[1] = TCS34725_COMMAND_BIT | reg;
  I2CMasterBuffer[2] = value;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
Example #20
0
err_t tsl2561Write8 (uint8_t reg, uint32_t value)
{
  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TSL2561_ADDRESS;
  I2CMasterBuffer[1] = reg;
  I2CMasterBuffer[2] = (value & 0xFF);
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
Example #21
0
static err_t adxl345Write8 (uint8_t reg, uint8_t value)
{
  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = ADXL345_ADDRESS;
  I2CMasterBuffer[1] = reg;
  I2CMasterBuffer[2] = value;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
error_t lsm303accelWrite8(uint8_t addr, uint8_t reg, uint8_t value)
{
  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = addr;
  I2CMasterBuffer[1] = reg;
  I2CMasterBuffer[2] = (value);
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
error_t lsm303accelRead8(uint8_t addr, uint8_t reg, uint8_t *value)
{
  /* Write transaction */
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = addr;
  I2CMasterBuffer[1] = reg;
  i2cEngine();

  /* Read transaction */
  I2CWriteLength = 0;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = addr | 0x01;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  /* Send received value back to the caller */
  *value = I2CSlaveBuffer[0];

  return ERROR_NONE;
}
Example #24
0
error_t lm75bWrite8 (uint8_t reg, uint32_t value)
{
  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = LM75B_ADDRESS;             // I2C device address
  I2CMasterBuffer[1] = reg;                       // Command register
  I2CMasterBuffer[2] = (value & 0xFF);            // Value to write
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  return ERROR_NONE;
}
pn532_error_t pn532_bus_Wakeup(void)
{
  pn532_error_t error = PN532_ERROR_NONE;
  byte_t abtWakeUp[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00 };

  pn532_pcb_t *pn532 = pn532GetPCB();

  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Sending Wakeup Sequence%s", CFG_PRINTF_NEWLINE);
  #endif
  error = pn532_bus_i2c_WriteData(abtWakeUp,sizeof(abtWakeUp));
  if (error)
  {
    #ifdef PN532_DEBUGMODE
      PN532_DEBUG("Wakeup Failed (Error: %d)%s", error, CFG_PRINTF_NEWLINE);
    #endif
    return error;
  }

  systickDelay(100);

  // Wait for the IRQ/Ready flag to indicate a response is ready
  if (!(pn532_bus_i2c_WaitForReady(PN532_I2C_TIMEOUT)))
  {
    #ifdef PN532_DEBUGMODE
    PN532_DEBUG ("Timed out waiting for IRQ/Ready%s", CFG_PRINTF_NEWLINE);
    #endif
    error = PN532_ERROR_READYSTATUSTIMEOUT;
  }

  // Read and discard the ACK frame
  I2CWriteLength = 0;
  I2CReadLength = 7;  // ACK + Ready bit = 7
  I2CMasterBuffer[0] = PN532_I2C_ADDRESS | PN532_I2C_READBIT;
  i2cEngine();
  systickDelay(1);

  // Wait for the IRQ/Ready flag to indicate a response is ready
  if (!(pn532_bus_i2c_WaitForReady(PN532_I2C_TIMEOUT)))
  {
    error = PN532_ERROR_READYSTATUSTIMEOUT;
  }
  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Wakeup Complete%s", CFG_PRINTF_NEWLINE);
  #endif

  pn532->state = PN532_STATE_READY;
  return error;
}
error_t lsm303accelRead48(uint8_t addr, uint8_t reg, uint8_t buffer[6])
{
  /* Write transaction */
  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = addr;
  I2CMasterBuffer[1] = reg | (0x80);
  i2cEngine();

  /* Read transaction */
  I2CWriteLength = 0;
  I2CReadLength = 6;
  I2CMasterBuffer[0] = addr | 0x01;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  uint8_t i;
  for (i = 0; i < 6; i++)
  {
    buffer[i] = I2CSlaveBuffer[i];
  }

  return ERROR_NONE;
}
Example #27
0
static i2c_error itg3200WriteByte (uint8_t address, uint8_t reg, uint32_t value)
{
    // Clear write buffers
    for ( i = 0; i < I2C_BUFSIZE; i++ )
    {
        I2CMasterBuffer[i] = 0x00;
    }

    I2CWriteLength = 3;
    I2CReadLength = 0;
    I2CMasterBuffer[0] = address;             // I2C device address
    I2CMasterBuffer[1] = reg;                       // Command register
    I2CMasterBuffer[2] = (value & 0xFF);            // Value to write
    return i2cEngine();
}
Example #28
0
static err_t adxl345Read8(uint8_t reg, uint8_t *value)
{
  I2CWriteLength = 2;
  I2CReadLength = 1;
  I2CMasterBuffer[0] = ADXL345_ADDRESS;
  I2CMasterBuffer[1] = reg;
  /* Append address w/read bit */
  I2CMasterBuffer[2] = ADXL345_ADDRESS | ADXL345_READBIT;
  /* Check if we got an ACK or TIMEOUT error */
  ASSERT_I2C_STATUS(i2cEngine());

  /* Shift values to create properly formed integer */
  *value = I2CSlaveBuffer[0];

  return ERROR_NONE;
}
Example #29
0
static HMC5843Error_e HMC5843Write8 (uint8_t reg, uint32_t value)
{
  // Clear write buffers
  for ( i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
  }

  I2CWriteLength = 3;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = HMC5843_ADDRESS;             // I2C device address
  I2CMasterBuffer[1] = reg;                       // Command register
  I2CMasterBuffer[2] = (value & 0xFF);            // Value to write
  i2cEngine();
  return HMC5843_ERROR_OK;
}
Example #30
0
tsl2561Error_t tsl2561WriteCmd (uint8_t cmd)
{
  // Clear write buffers
  uint32_t i;
  for ( i = 0; i < I2C_BUFSIZE; i++ )
  {
    I2CMasterBuffer[i] = 0x00;
  }

  I2CWriteLength = 2;
  I2CReadLength = 0;
  I2CMasterBuffer[0] = TSL2561_ADDRESS;       // I2C device address
  I2CMasterBuffer[1] = cmd;                   // Command register
  i2cEngine();
  return TSL2561_ERROR_OK;
}