Example #1
0
void ADXL345_AccInit(void)
{
	uint8_t power_ctl = 0x08, dataformat = 0x0B, bw_rate = 0x0B;
	ADXL345_Write((uint8_t)ADXL345_I2C_ADDR, 0x2D, &power_ctl);
	ADXL345_Write((uint8_t)ADXL345_I2C_ADDR, 0x31, &dataformat);
	ADXL345_Write((uint8_t)ADXL345_I2C_ADDR, 0x2C, &bw_rate);
}
/**************************************************************************************************
* Function ADXL345_Init()
* -------------------------------------------------------------------------------------------------
* Overview: Function that initializes ADXL345
* Input: Nothing
* Output: return 0 for OK; return _ACCEL_ERROR for ERROR
**************************************************************************************************/
char ADXL345_Init(void)
{
  char id = 0x00;

  // Go into standby mode to configure the device.
  ADXL345_Write(0x2D, 0x00);

  id = ADXL345_Read(0x00);

  if (id != 0xE5)
  {
    return _ACCEL_ERROR;
  }
  else
  {
    ADXL345_Write(_DATA_FORMAT, 0x08);       // Full resolution, +/-2g, 4mg/LSB, right justified
    ADXL345_Write(_BW_RATE, 0x0A);           // Set 100 Hz data rate
    ADXL345_Write(_FIFO_CTL, 0x80);          // stream mode
    ADXL345_Write(_POWER_CTL, 0x08);         // POWER_CTL reg: measurement mode
    return 0x00;
  }
}
Example #3
0
bool Accel_Init(void)
{
  unsigned char id;

  // Go into standby mode to configure the device.
  ADXL345_Write(0x2D, 0x00);

  id = ADXL345_Read(0x00);
  if (id != 0xE5) {
    return false;
  }

  ADXL345_Write(_POWER_CTL, 0x00);         // Go into standby mode to configure the device
  ADXL345_Write(_DATA_FORMAT, 0x08);       // Full resolution, +/-2g, 4mg/LSB, right justified
  ADXL345_Write(_BW_RATE, 0x0A);           // Set 100 Hz data rate
  ADXL345_Write(_FIFO_CTL, 0x80);          // stream mode
  ADXL345_Write(_POWER_CTL, 0x08);         // POWER_CTL reg: measurement mode*/

  return 0x00;
}