Exemple #1
0
/**************************************************************************************************
 * @fn          HalMagTest
 *
 * @brief       Run a sensor self-test
 *
 * @return      TRUE if passed, FALSE if failed
 **************************************************************************************************/
bool HalMagTest(void)
{
  uint8 val;

  // Select this sensor on the I2C bus
  HalMagSelect();

  // Check who-am-i register
  ST_ASSERT(HalSensorReadReg(MAG_REG_ADDR_WHO_AM_I, &val, sizeof(val)));
  ST_ASSERT(val==WHO_AM_I_VALUE);

  // Check CTRL_REG1 in standby mode
  ST_ASSERT(HalSensorReadReg(MAG_REG_ADDR_CTRL_1, &val, sizeof(val)));
  ST_ASSERT(val==MAG_REG_CTRL_OFF);

  // Check that CTRL_REG1 can be written
  val = CTRL1_TEST_VALUE;
  ST_ASSERT(HalSensorWriteReg(MAG_REG_ADDR_CTRL_1, &val, sizeof(val)));
  ST_ASSERT(HalSensorReadReg(MAG_REG_ADDR_CTRL_1, &val, sizeof(val)));
  ST_ASSERT(val==CTRL1_TEST_VALUE);

  // Restore default value
  val = MAG_REG_CTRL_OFF;
  ST_ASSERT(HalSensorWriteReg(MAG_REG_ADDR_CTRL_1, &val, sizeof(val)));

  // Check that the sensor is in standby mode
  ST_ASSERT(HalSensorReadReg(MAG_REG_ADDR_SYSMOD, &val, sizeof(val)));
  ST_ASSERT(val==0);

  return TRUE;
}
/**************************************************************************************************
 * @fn          HalINFRead
 *
 * @brief       Read the sensor voltage and sensor temperature registers
 *
 * @param       Voltage and temperature in raw format (2 + 2 bytes)
 *
 * @return      TRUE if valid data
 **************************************************************************************************/
bool HalINFRead(uint8 addr, uint8 *pBuf, uint8 nBytes) {
	bool success;
	HalINFTurnOn();
	// Read the sensor registers
	success = HalSensorReadReg(addr, pBuf, nBytes);
	if (success) {
	}
	return success;
}
Exemple #3
0
/**************************************************************************************************
* @fn          HalHumiInit
*
* @brief       Initialise the humidity sensor driver
*
* @return      none
**************************************************************************************************/
void HalHumiInit(void)
{
  HalHumiSelect();

  // Set 11 bit resolution
  HalSensorReadReg(SHT21_CMD_READ_U_R,&usr,1);
  usr &= USR_REG_RES_MASK;
  usr |= USR_REG_11BITRES;
  HalSensorWriteReg(SHT21_CMD_WRITE_U_R,&usr,1);
  success = FALSE;
}
Exemple #4
0
/**************************************************************************************************
 * @fn          HalIRTempTest
 *
 * @brief       Run a sensor self-test
 *
 * @return      TRUE if passed, FALSE if failed
 **************************************************************************************************/
bool HalIRTempTest(void)
{
  uint16 val;

  // Select this sensor on the I2C bus
  HalIRTempSelect();

  // Check manufacturer ID
  ST_ASSERT(HalSensorReadReg(TMP006_REG_MANF_ID, (uint8 *)&val, IRTEMP_REG_LEN));
  val = (LO_UINT16(val) << 8) | HI_UINT16(val);
  ST_ASSERT(val == TMP006_VAL_MANF_ID);

  // Reset sensor
  ST_ASSERT(HalSensorWriteReg(TMP006_REG_ADDR_CONFIG, configSensorReset, IRTEMP_REG_LEN));

  // Check config register (reset)
  ST_ASSERT(HalSensorReadReg(TMP006_REG_ADDR_CONFIG, (uint8 *)&val, IRTEMP_REG_LEN));
  val = ((LO_UINT16(val) << 8) | HI_UINT16(val));
  ST_ASSERT(val == TMP006_VAL_CONFIG_RESET);

  // Turn sensor off
  ST_ASSERT(HalSensorWriteReg(TMP006_REG_ADDR_CONFIG, configSensorOff,IRTEMP_REG_LEN));

  // Check config register (off)
  ST_ASSERT(HalSensorReadReg(TMP006_REG_ADDR_CONFIG, (uint8 *)&val, IRTEMP_REG_LEN));
  val = ((LO_UINT16(val) << 8) | HI_UINT16(val));
  ST_ASSERT(val == TMP006_VAL_CONFIG_OFF);

  // Turn sensor on
  ST_ASSERT(HalSensorWriteReg(TMP006_REG_ADDR_CONFIG, configSensorOn, IRTEMP_REG_LEN));

  // Check config register (on)
  ST_ASSERT(HalSensorReadReg(TMP006_REG_ADDR_CONFIG, (uint8 *)&val, IRTEMP_REG_LEN));
  val = ((LO_UINT16(val) << 8) | HI_UINT16(val));
  ST_ASSERT(val == TMP006_VAL_CONFIG_ON);

  // Turn sensor off
  ST_ASSERT(HalSensorWriteReg(TMP006_REG_ADDR_CONFIG, configSensorOff, IRTEMP_REG_LEN));

  return TRUE;
}
Exemple #5
0
/**************************************************************************************************
* @fn          HalHumiTest
*
* @brief       Humidity sensor self test
*
* @return      none
**************************************************************************************************/
bool HalHumiTest(void)
{
  uint8 val;

  HalHumiSelect();

  // Verify default value
  ST_ASSERT(HalSensorReadReg(SHT21_CMD_READ_U_R,&val,1));
  ST_ASSERT(val==usr);

  return TRUE;
}
Exemple #6
0
/**************************************************************************************************
 * @fn          HalIRTempRead
 *
 * @brief       Read the sensor voltage and sensor temperature registers
 *
 * @param       Voltage and temperature in raw format (2 + 2 bytes)
 *
 * @return      TRUE if valid data
 **************************************************************************************************/
bool HalIRTempRead(uint8 *pBuf)
{
  uint16 v;
  uint16 t;
  bool success;

  if (irtSensorState != TMP006_DATA_READY)
  {
    return FALSE;
  }

  HalIRTempSelect();

  // Read the sensor registers
  success = HalSensorReadReg(TMP006_REG_ADDR_VOLTAGE, (uint8 *)&v,IRTEMP_REG_LEN );
  if (success)
  {
    success = HalSensorReadReg(TMP006_REG_ADDR_TEMPERATURE, (uint8 *)&t,IRTEMP_REG_LEN );
  }

  if (success)
  {
    // Store values
    pBuf[0] = HI_UINT16( v );
    pBuf[1] = LO_UINT16( v );
    pBuf[2] = HI_UINT16( t );
    pBuf[3] = LO_UINT16( t );
  }

  // Turn off sensor
  if (HalSensorWriteReg(TMP006_REG_ADDR_CONFIG, configSensorOff, IRTEMP_REG_LEN))
  {
    irtSensorState = TMP006_OFF;
  }
  HalDcDcControl(ST_IRTEMP,false);

  return success;
}
Exemple #7
0
/**************************************************************************************************
 * @fn          HalMagStatus
 *
 * @brief       Read the magnetometer status
 *
 * @return      none
 **************************************************************************************************/
Magnetometer_States_t HalMagStatus( void )
{
  if( sensorState == MAG3110_IDLE)
  {
    uint8 status = 0;

    HalMagSelect();
    HalSensorReadReg( MAG_REG_ADDR_DR_STATUS, &status, 1);
    if(status!=0)
    {
      sensorState = MAG3110_DATA_READY;
    }
  }

  return sensorState;
}
Exemple #8
0
/**************************************************************************************************
 * @fn          HalIRTempStatus
 *
 * @brief       Read the state of the sensor
 *
 * @return      none
 **************************************************************************************************/
IRTemperature_States_t HalIRTempStatus(void)
{
  if (irtSensorState != TMP006_OFF)
  {
    bool success;
    uint16 v;

    // Select this sensor on the I2C bus
    HalIRTempSelect();

    // Read the data ready bit
    success = HalSensorReadReg(TMP006_REG_ADDR_CONFIG, (uint8 *)&v,IRTEMP_REG_LEN );
    if ((v & DATA_RDY_BIT) && success)
    {
      irtSensorState = TMP006_DATA_READY;
    }
  }

  return irtSensorState;
}
Exemple #9
0
/**************************************************************************************************
* @fn          HalMagRead
*
* @brief       Read data from the magnetometer
*
* @param       pBuf - buffer to hold the data
*
* @return      TRUE if valid data
*/
bool HalMagRead(uint8 *pBuf)
{
  uint8 tmp[MAG_REG_READ_ALL_LEN];
  bool f;

  HalMagSelect();

  f = HalSensorReadReg(MAG_REG_ADDR_READ_START,tmp,MAG_REG_READ_ALL_LEN);
  if (f)
  {
    // Swap bytes in each value-pair
    pBuf[0] = tmp[1];
    pBuf[1] = tmp[0];
    pBuf[2] = tmp[3];
    pBuf[3] = tmp[2];
    pBuf[4] = tmp[5];
    pBuf[5] = tmp[4];
  }
  sensorState = MAG3110_IDLE;

  return f;
}