Exemple #1
0
static unsigned char adxl345_reg_multi_read(unsigned char addr, unsigned char n, unsigned char *val)
{
	/* send address we're reading from */
	if (HalI2CWrite(1, &addr) == 1) {
		/* now read data */
		return HalI2CRead(n, val);
	}
	return 0;
}
/**************************************************************************************************
 * @fn          HalMotionI2cRead
 *
 * @brief       This function implements the I2C protocol to read from the IMU-3000 gyroscope.
 *
 * input parameters
 *
 * @param       device - which device is being written
 *              addr - which register to read
 *              numBytes - number of bytes to read
 *              pBuf - pointer to buffer to place data
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************/
void HalMotionI2cRead( halMotionDevice_t device, uint8 addr, uint8 numBytes, uint8 *pBuf )
{
  uint8 localAddr = addr;

  /* Send address we're reading from */
  HalI2CWrite( HalMotionDeviceAddressTable[device], 1, &localAddr );

  /* Now read data */
  HalI2CRead( HalMotionDeviceAddressTable[device], numBytes, pBuf );
}
/**************************************************************************************************
 * @fn          HalSensorReadReg
 *
 * @brief       This function implements the I2C protocol to read from a sensor. The sensor must
 *              be selected before this routine is called.
 *
 * @param       addr - which register to read
 * @param       pBuf - pointer to buffer to place data
 * @param       nBytes - numbver of bytes to read
 *
 * @return      TRUE if the required number of bytes are reveived
 **************************************************************************************************/
bool HalSensorReadReg(uint8 addr, uint8 *pBuf, uint8 nBytes)
{
  uint8 i = 0;

  /* Send address we're reading from */
  if (HalI2CWrite(1,&addr) == 1)
  {
    /* Now read data */
    i = HalI2CRead(nBytes,pBuf);
  }

  return i == nBytes;
}
Exemple #4
0
/**************************************************************************************************
* @fn          HalHumiReadData
*
* @brief       This function implements the I2C protocol to read from the SHT21.
*
* @param       pBuf - pointer to buffer to place data
*
* @param       nBytes - number of bytes to read
*
* @return      TRUE if the required number of bytes are received
**************************************************************************************************/
static bool HalHumiReadData(uint8 *pBuf, uint8 nBytes)
{
  /* Read data */
  return HalI2CRead(nBytes,pBuf ) == nBytes;
}