예제 #1
0
uint16_t ov7670GetDeviceID(void)
{
	uint16_t id = 0;
	
	i2cdevReadByte(I2Cx, devAddr, 0x0A, &buffer[0]);
	i2cdevReadByte(I2Cx, devAddr, 0x0B, &buffer[1]);
	
	id += buffer[0];
	id = (id << 8) + buffer[1];
	
  return id;
}
예제 #2
0
/** Verify the I2C connection.
 * Make sure the device is connected and responds as expected.
 * @return True if connection is valid, false otherwise
 */
bool ak8963TestConnection()
{
  if (i2cdevReadByte(I2Cx, devAddr, AK8963_RA_WIA, buffer) == 1)
  {
    return (buffer[0] == 0x48);
  }
  return false;
}
예제 #3
0
bool i2cdevReadBits(I2C_TypeDef *I2Cx, uint8_t devAddress, uint8_t memAddress,
                    uint8_t bitStart, uint8_t length, uint8_t *data)
{
  bool status;
  uint8_t byte;

  if ((status = i2cdevReadByte(I2Cx, devAddress, memAddress, &byte)) == TRUE)
  {
      uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
      byte &= mask;
      byte >>= (bitStart - length + 1);
      *data = byte;
  }
예제 #4
0
bool ak8963SelfTest()
{
  bool testStatus = true;
  int16_t mx, my, mz;  // positive magnetometer measurements
  uint8_t confSave;
  uint8_t timeout = 20;

  // Save register values
  if (i2cdevReadByte(I2Cx, devAddr, AK8963_RA_CNTL, &confSave) == false)
  {
    // TODO: error handling
    return false;
  }

  // Power down
  ak8963SetMode(AK8963_MODE_POWERDOWN);
  ak8963SetSelfTest(true);
  ak8963SetMode(AK8963_MODE_16BIT | AK8963_MODE_SELFTEST);
  // Clear ST1 by reading ST2
  ak8963GetOverflowStatus();
  while (!ak8963GetDataReady() && timeout--)
  {
    vTaskDelay(M2T(1));
  }
  ak8963GetHeading(&mx, &my, &mz);
  // Power down
  ak8963SetMode(AK8963_MODE_POWERDOWN);

  if (ak8963EvaluateSelfTest(AK8963_ST_X_MIN, AK8963_ST_X_MAX, mx, "X") &&
      ak8963EvaluateSelfTest(AK8963_ST_Y_MIN, AK8963_ST_Y_MAX, my, "Y") &&
      ak8963EvaluateSelfTest(AK8963_ST_Z_MIN, AK8963_ST_Z_MAX, mz, "Z"))
   {
    DEBUG_PRINT("Self test [OK].\n");
  }
  else
  {
    testStatus = false;
  }

  // Power up with saved config
  ak8963SetMode(confSave);

  return testStatus;
}
예제 #5
0
/** Get identification byte C
 * @return ID_A byte (should be 00110011, ASCII value '3')
 */
uint8_t hmc5883lGetIDC()
{
  i2cdevReadByte(I2Cx, devAddr, HMC5883L_RA_ID_C, buffer);
  return buffer[0];
}
예제 #6
0
uint8_t ak8963GetAdjustmentZ()
{
  i2cdevReadByte(I2Cx, devAddr, AK8963_RA_ASAZ, buffer);
  return buffer[0];
}
예제 #7
0
// CNTL register
uint8_t ak8963GetMode()
{
  i2cdevReadByte(I2Cx, devAddr, AK8963_RA_CNTL, buffer);
  return buffer[0];
}
예제 #8
0
uint8_t ak8963GetInfo()
{
  i2cdevReadByte(I2Cx, devAddr, AK8963_RA_INFO, buffer);
  return buffer[0];
}
예제 #9
0
uint8_t ak8963GetDeviceID()
{
  i2cdevReadByte(I2Cx, devAddr, AK8963_RA_WIA, buffer);
  return buffer[0];
}