Ejemplo n.º 1
0
int sht21_humidity(void)
{
  int val;

  i2c_enable();
  /* For for about 15ms before the SHT11 can be used */
  sht21_timer = RTIMER_NOW();
  while(RTIMER_CLOCK_LT(RTIMER_NOW(), sht21_timer + (RTIMER_SECOND/1000)*15));

  buf[0] = 0xe5;
  i2c_transmitinit(0x40, 1, buf);
  while(!i2c_transferred()) ;

  /* Wait for measurement about 85ms */
  sht21_timer = RTIMER_NOW();
  while(RTIMER_CLOCK_LT(RTIMER_NOW(), sht21_timer + (RTIMER_SECOND/1000)*85));

  i2c_receiveinit(0x40, 3, buf);
  while(!i2c_transferred()) ;

  val = (int)(buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]);

//  i2c_disable();
  /* return relative humidity * 100 (0.04 % accuracy) */
  return (-6.0 + (125.0*((val>>16)&0x0000fffc))/0x10000)*100;
}
Ejemplo n.º 2
0
/*############################## FIFO COUNT FUNCTION ##################################  */
uint16_t mpu9150_FIFO_count(uint8_t *buffer) {
	prepareRead(MPU9150_FIFO_COUNT_H);

	i2c_receiveinit( MPU9150_I2C_ADDR, 2, buffer ) ;
	while(!i2c_transferred()) /* Wait for transfer */ ;
	
	uint16_t fifo_count = ((buffer[0]<<8) | buffer[1]);
        printf("FIFO count in bits: %i and in bytes %i\n", fifo_count, fifo_count/8);
        return fifo_count / 8;
}
Ejemplo n.º 3
0
/*############################## GET DATA FUNCTION ##################################  */
void mpu9150_get_data(uint8_t *buffer) {
  // Poll number of new measurements to read from the FIFO:
  //uint8_t set[] = {MPU9150_FIFO_COUNT_H,0};
  prepareRead(MPU9150_FIFO_R_W);
  
  i2c_receiveinit( MPU9150_I2C_ADDR, 2, buffer ) ;
  while(!i2c_transferred());
  
  uint16_t fifo_count = ((buffer[0]<<8) | buffer[1]);
}
Ejemplo n.º 4
0
/*######################### GET DATA FUNCTION WITH SIZE ############################## */
void mpu9150_get_data_size(uint8_t *buffer, int size) {
  // Poll number of new measurements to read from the FIFO:
  prepareRead(MPU9150_FIFO_R_W);
  
  //size = 2;
  size = 18;
  
  printf("Prepared FIFO for reading %i bytes...\n",size);
  
  i2c_receiveinit( MPU9150_I2C_ADDR, size, buffer ) ;
  while(!i2c_transferred());
  
  uint16_t fifo_count = ((buffer[0]<<8) | buffer[1]);
}
Ejemplo n.º 5
0
void
accm_read_stream(u8_t reg, u8_t len, u8_t *whereto) {
  u8_t rtx = reg;
  PRINTFDEBUG("READ_STR %u B from 0x%02X\n", len, reg);

  /* transmit the register to start reading from */
  i2c_transmitinit(ADXL345_ADDR);
  while (i2c_busy());
  i2c_transmit_n(1, &rtx);
  while (i2c_busy());

  /* receive the data */
  i2c_receiveinit(ADXL345_ADDR);
  while (i2c_busy());
  i2c_receive_n(len, whereto);
  while (i2c_busy());
}
Ejemplo n.º 6
0
u8_t
accm_read_reg(u8_t reg) {
  u8_t retVal = 0;
  u8_t rtx = reg;
  PRINTFDEBUG("READ_REG 0x%02X\n", reg);

  /* transmit the register to read */
  i2c_transmitinit(ADXL345_ADDR);
  while (i2c_busy());
  i2c_transmit_n(1, &rtx);
  while (i2c_busy());

  /* receive the data */
  i2c_receiveinit(ADXL345_ADDR);
  while (i2c_busy());
  i2c_receive_n(1, &retVal);
  while (i2c_busy());

  return retVal;
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
static uint16_t
sht25_read_reg(uint8_t reg)
{
  uint8_t buf[] = { 0x00, 0x00 };
  uint16_t retval;
  uint8_t rtx = reg;

  /* transmit the register to read */
  i2c_transmitinit(SHT25_ADDR);
  while(i2c_busy());
  i2c_transmit_n(1, &rtx);
  while(i2c_busy());
  /* receive the data */
  i2c_receiveinit(SHT25_ADDR);
  while(i2c_busy());
  i2c_receive_n(2, &buf[0]);
  while(i2c_busy());

  retval = (uint16_t)(buf[0] << 8 | (buf[1]));
  return retval;
}
Ejemplo n.º 8
0
void mma7660_acc(int *x, int *y, int *z)
{
  int tmp;
  i2c_enable();

  /* Read data */
  buf[0] = XOUT;
  i2c_transmitinit(ADDR, 1, buf);
  while(!i2c_transferred()) ;
  i2c_receiveinit(ADDR, 3, buf);
  while(!i2c_transferred()) ;

  i2c_disable();

  tmp = (signed char)((buf[0] & 0x20) ? (buf[0] | 0xC0) : (buf[0] & 0x3F));
  *x = (tmp*150)/32;
  tmp = (signed char)((buf[1] & 0x20) ? (buf[1] | 0xC0) : (buf[1] & 0x3F));
  *y = (tmp*150)/32;
  tmp = (signed char)((buf[2] & 0x20) ? (buf[2] | 0xC0) : (buf[2] & 0x3F));
  *z = (tmp*150)/32;
}
Ejemplo n.º 9
0
uint8_t
tlc59116_read_reg(uint8_t reg)
{
  uint8_t retVal = 0;
  uint8_t rtx = reg;

  PRINTFDEBUG("READ_REG 0x%02X\n", reg);

  /* transmit the register to read */
  i2c_transmitinit(TLC59116_ADDR);
  while(i2c_busy());
  i2c_transmit_n(1, &rtx);
  while(i2c_busy());

  /* receive the data */
  i2c_receiveinit(TLC59116_ADDR);
  while(i2c_busy());
  i2c_receive_n(1, &retVal);
  while(i2c_busy());

  return retVal;
}
Ejemplo n.º 10
0
/*
 * Function to return the WHO_AM_I value
 * of the mpu9150 chip.
*/
void mpu9150_who_am_i(uint8_t *buffer) {
   prepareRead(MPU9150_WHO_AM_I);
     
   i2c_receiveinit( MPU9150_I2C_ADDR, 2, buffer ); //need to receive two bytes, otherwise we get ERROR I2C: Arbitration lost
   while(!i2c_transferred()); /* Wait for transfer */
}