Changeset - 645e46f4898d
[Not reviewed]
tip default
0 2 0
Ethan Zonca (ethanzonca) - 9 years ago 2017-02-08 16:32:25
e@ethanzonca.com
Update scale for bme280 to tenths of percent, disable lps25h
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
Include/config.h
Show inline comments
 
//
 
// Depth Select Configuration
 
//
 
 
#ifndef CONFIG_H
 
#define CONFIG_H
 
 
 
// --------------------------------------------------------------------------
 
// Transmitter config (si446x.c)
 
// --------------------------------------------------------------------------
 
 
// Transmit power (0-0x7F, 0mW - 40mw?)
 
#define SI446x_POWER 0x40 // 0x40 for jake launch
 
 
#define TUNE_FREQUENCY 433500000UL
 
 
 
// Internal macros
 
#define hal_init HAL_Init
 
 
 
// Uncomment if using legacy LPS25h pressure sensor
 
#define LPS25H
 
//#define LPS25H
 
 
 
#define FRIENDLY_MODE
 
#define FRIENDLY_TIMEOUT  1800 // 1800 // seconds before reducing tx rate
 
#define FRIENDLY_TX_RATE 60000 // milliseconds tx rate after timeout elapsed
 
 
// --------------------------------------------------------------------------
 
// ADC config (adc.c)
 
// --------------------------------------------------------------------------
 
 
// Temperature sensor offset (die temperature from ambient, esimate, in Celcius)
 
#define ADC_TEMPERATURE_OFFSET -10
 
 
 
// --------------------------------------------------------------------------
 
// AX.25 config (ax25.c)
 
// --------------------------------------------------------------------------
 
 
// TX delay in milliseconds
 
#define TX_DELAY      70
 
 
// Maximum packet delay
 
#define MAX_PACKET_LEN 512  // bytes
 
 
 
// --------------------------------------------------------------------------
 
// APRS config (aprs.c)
 
// --------------------------------------------------------------------------
 
 
// Set your callsign and SSID here. Common values for the SSID are
 
// (from http://zlhams.wikidot.com/aprs-ssidguide):
 
//
 
// - Balloons:  11
 
// - Cars:       9
 
// - Home:       0
 
// - IGate:      5
 
#define S_CALLSIGN      "S"
 
#define S_CALLSIGN_ID   1
 
 
// Destination callsign: APRS (with SSID=0) is usually okay.
 
#define D_CALLSIGN      ""
 
#define D_CALLSIGN_ID   0
 
 
// Digipeating paths:
 
// (read more about digipeating paths here: http://wa8lmf.net/DigiPaths/ )
 
// The recommended digi path for a balloon is WIDE2-1 or pathless. The default
 
// is pathless. Uncomment the following two lines for WIDE2-1 path:
 
//#define DIGI_PATH1      "WIDE2"
Source/bme280.c
Show inline comments
 
@@ -68,97 +68,97 @@ bool bme280_init(void)
 
 
 
	if (result != 0x60)
 
	{
 
		return false;
 
	}
 
 
	bme280_write(BME280_CTRL_MEAS_REG, 0x00);
 
	bme280_write(BME280_CONFIG_REG, 0b01100000); // 4hz sampling rate
 
	bme280_write(BME280_CTRL_HUMIDITY_REG, 0x01); //0b00000001, oversample*1
 
	bme280_write(BME280_CTRL_MEAS_REG, 0x27); //0b00100111
 
 
 
	//calibrate
 
 
	dig_T1 = ((uint16_t)((bme280_read_byte(BME280_DIG_T1_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_T1_LSB_REG)));
 
	dig_T2 = ((int16_t)((bme280_read_byte(BME280_DIG_T2_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_T2_LSB_REG)));
 
	dig_T3 = ((int16_t)((bme280_read_byte(BME280_DIG_T3_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_T3_LSB_REG)));
 
 
	dig_P1 = ((uint16_t)((bme280_read_byte(BME280_DIG_P1_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P1_LSB_REG)));
 
	dig_P2 = ((int16_t)((bme280_read_byte(BME280_DIG_P2_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P2_LSB_REG)));
 
	dig_P3 = ((int16_t)((bme280_read_byte(BME280_DIG_P3_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P3_LSB_REG)));
 
	dig_P4 = ((int16_t)((bme280_read_byte(BME280_DIG_P4_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P4_LSB_REG)));
 
	dig_P5 = ((int16_t)((bme280_read_byte(BME280_DIG_P5_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P5_LSB_REG)));
 
	dig_P6 = ((int16_t)((bme280_read_byte(BME280_DIG_P6_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P6_LSB_REG)));
 
	dig_P7 = ((int16_t)((bme280_read_byte(BME280_DIG_P7_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P7_LSB_REG)));
 
	dig_P8 = ((int16_t)((bme280_read_byte(BME280_DIG_P8_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P8_LSB_REG)));
 
	dig_P9 = ((int16_t)((bme280_read_byte(BME280_DIG_P9_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_P9_LSB_REG)));
 
 
	dig_H1 = ((uint8_t)(bme280_read_byte(BME280_DIG_H1_REG)));
 
	dig_H2 = ((int16_t)((bme280_read_byte(BME280_DIG_H2_MSB_REG) << 8) + bme280_read_byte(BME280_DIG_H2_LSB_REG)));
 
	dig_H3 = ((uint8_t)(bme280_read_byte(BME280_DIG_H3_REG)));
 
	dig_H4 = ((int16_t)((bme280_read_byte(BME280_DIG_H4_MSB_REG) << 4) + (bme280_read_byte(BME280_DIG_H4_LSB_REG) & 0x0F)));
 
	dig_H5 = ((int16_t)((bme280_read_byte(BME280_DIG_H5_MSB_REG) << 4) + ((bme280_read_byte(BME280_DIG_H4_LSB_REG) >> 4) & 0x0F)));
 
	dig_H6 = ((uint8_t)bme280_read_byte(BME280_DIG_H6_REG));
 
 
	return true;
 
}
 
 
 
// Acquire new readings from sensor and update values in RAM
 
void bme280_update(void)
 
{
 
	uint8_t result[8];
 
	bme280_read(BME280_PRESSURE_MSB_REG, result, 8);
 
 
	pressure = bme280_convert_pressure(result[0] << 12 | result[1] << 4 | (result[2] & 0xf0) << 0) / 256 / 10; // convert to mBar/hPa
 
	temperature = bme280_convert_temperature(result[3] << 12 | result[4] << 4 | (result[5] & 0xf0) << 0); // 0.01C
 
	humidity = bme280_convert_humidity(result[6] << 8 | result[7] << 0) / 1024; // 0.01% RH
 
	humidity = bme280_convert_humidity(result[6] << 8 | result[7] << 0) / (1024/10); // 0.1% RH
 
}
 
 
 
// returns pressure in mb with 0.1mb resolution
 
int32_t bme280_get_pressure(void)
 
{
 
	return pressure;
 
}
 
 
// returns temperature in DegC with 0.01 DegC resolution
 
int32_t bme280_get_temperature(void)
 
{
 
 
	return temperature;
 
}
 
 
// returns humidity in %RH with 0.01% resolution
 
int32_t bme280_get_humidity(void)
 
{
 
 
	return humidity;
 
}
 
 
 
 
 
void bme280_read(uint8_t register_address, uint8_t* data, uint8_t length)
 
{
 
	HAL_I2C_Mem_Read(&hi2c1, BME280_I2C_ADDR, register_address, 1, data, length, 500);
 
}
 
 
uint8_t bme280_read_byte(uint8_t register_address)
 
{
 
	uint8_t result;
 
	bme280_read(register_address, &result, 1);
 
	return result;
 
}
 
 
void bme280_write(uint8_t register_address, uint8_t data)
 
{
 
	//register_address &= 0x7F;
 
	uint8_t data_arr[1];
 
	data_arr[0] = data;
 
	HAL_I2C_Mem_Write(&hi2c1, BME280_I2C_ADDR, register_address, 1, data_arr, 1, 500);
 
}
 
 
// Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC.
 
// t_fine carries fine temperature as global value
0 comments (0 inline, 0 general)