Changeset - f2c57ce0cd7b
[Not reviewed]
default
2 3 2
Ethan Zonca (ethanzonca) - 9 years ago 2017-01-24 10:20:42
e@ethanzonca.com
Refactor old pressure code and make optional. Fix high power output due to multiple Si446x power definitions
5 files changed with 54 insertions and 21 deletions:
0 comments (0 inline, 0 general)
Include/config.h
Show inline comments
 
@@ -10,18 +10,20 @@
 
// Transmitter config (si446x.c)
 
// --------------------------------------------------------------------------
 
 
// Transmit power (0-0x7F, 0mW - 40mw?)
 
#define SI446x_POWER 0x02
 
 
#define TUNE_FREQUENCY 433000000UL
 
#define TUNE_FREQUENCY 433500000UL
 
 
// Internal macros
 
#define hal_init HAL_Init
 
 
 
// Uncomment if using legacy LPS25h pressure sensor
 
//#define LPS25H
 
 
 
// --------------------------------------------------------------------------
 
// ADC config (adc.c)
 
// --------------------------------------------------------------------------
 
 
@@ -41,14 +43,12 @@
 
 
 
// --------------------------------------------------------------------------
 
// APRS config (aprs.c)
 
// --------------------------------------------------------------------------
 
 
#define SI446x_POWER 0x7f
 
 
// 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
Include/lps25h.h
Show inline comments
 
file renamed from Include/pressure.h to Include/lps25h.h
 
#ifndef PRESSURE_H
 
#define PRESSURE_H
 
#ifndef LPS25H_H
 
#define LPS25H_H
 
 
#include "stm32f0xx_hal.h"
 
 
 
#define PIN_SENSORS_SDA GPIO_PIN_7
 
#define PIN_SENSORS_SCL GPIO_PIN_6
 
@@ -20,17 +20,17 @@
 
#define PRESSURE_CTRL1_7HZ 	  0b00100000
 
#define PRESSURE_CTRL1_12_5HZ 0b00110000
 
#define PRESSURE_CTRL1_25HZ   0b01000000
 
 
#define PRESSURE_CTRL1_PWRUP 0b10000000
 
 
void pressure_init(void);
 
void pressure_read(void);
 
void pressure_updatevalues(void);
 
void lps25h_init(void);
 
void lps25h_read(void);
 
void lps25h_updatevalues(void);
 
 
int32_t pressure_gettemp(void);
 
int32_t pressure_getpressure(void);
 
int32_t lps25h_get_temperature(void);
 
int32_t lps25h_get_pressure(void);
 
 
I2C_HandleTypeDef* pressure_get_i2c_handle(void);
 
I2C_HandleTypeDef* lps25h_get_i2c_handle(void);
 
#endif
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab
Libraries/aprs/aprs.c
Show inline comments
 
@@ -21,14 +21,17 @@
 
 */
 

	
 
#include <string.h>
 
#include <stdlib.h>
 

	
 
#include "config.h"
 
//#include "pressure.h"
 
#ifdef LPS25H
 
	#include "lps25h.h"
 
#else
 
#include "bme280.h"
 
#endif
 
#include "aprs.h"
 
#include "gps.h"
 
//#include "gps.h"
 
//#include "adc.h"
 
#include "ax25.h"
 
#include "system/adc.h"
 
@@ -77,23 +80,39 @@ void aprs_send(void)
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Altitude
 
  snprintf(tmpBuffer, 128, "%d,", gps_getdata()->altitude);
 
  ax25_send_string(tmpBuffer);
 

	
 

	
 
#ifdef LPS25H
 
  // Pressure
 
  snprintf(tmpBuffer, 128, "%d,", lps25h_get_pressure());
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Temperature
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_temperature());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Humidity
 
  snprintf(tmpBuffer, 128, "0,");
 
  ax25_send_string(tmpBuffer);
 

	
 
#else
 
  // Pressure
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_pressure());
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Temperature
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_temperature());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Humidity
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_humidity());
 
  ax25_send_string(tmpBuffer);
 
#endif
 

	
 
  // HDOP
 
  snprintf(tmpBuffer, 128, "%u,", gps_getdata()->pdop);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Heading
Source/lps25h.c
Show inline comments
 
file renamed from Source/pressure.c to Source/lps25h.c
 
//
 
// Sensors: Reads pressure and e-compass sensors over I2C and stores readings in queryable internal data structures
 
//
 
 
#include "pressure.h"
 
#include "lps25h.h"
 
#include "stm32f0xx_hal.h"
 
 
 
#include "config.h"
 
 
 
@@ -17,13 +17,13 @@ static int32_t temp_celsius = 0;
 
 
static uint8_t sensors_pressurebuf[8]; // Buffer for i2c rx pressure data
 
static uint8_t sensors_pressure_freshdata = 0; // If pressure sensor has fresh data
 
 
 
// Initialize pressure sensor and E-compass
 
void pressure_init(void)
 
void lps25h_init(void)
 
{
 
	GPIO_InitTypeDef GPIO_InitStruct;
 
 
	// I2C Pins
 
    GPIO_InitStruct.Pin = PIN_SENSORS_SCL|PIN_SENSORS_SDA;
 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
 
@@ -60,13 +60,13 @@ void pressure_init(void)
 
	HAL_Delay(10);
 
	res = HAL_I2C_Mem_Write(&hi2c1, PRESSURE_ADDRESS, 0x20, 1, temp, 1, 500);
 
}
 
 
 
// Initiate interrupt-based read of engineering sensors
 
void pressure_read(void)
 
void lps25h_read(void)
 
{
 
	// Start reading pressure sensor
 
	HAL_Delay(10);
 
	volatile  HAL_StatusTypeDef res = HAL_I2C_Mem_Read(&hi2c1, PRESSURE_ADDRESS, PRESSURE_PRESS_REGXL | PRESSURE_AUTOINC, 1, sensors_pressurebuf, 5, 500);
 
 
	// Consume fresh data flag
 
@@ -85,27 +85,27 @@ void pressure_read(void)
 
		temp_celsius = 42.5 + temp_out / 480.0;
 
 
}
 
 
 
// Get current temperature in Celsius
 
int32_t pressure_gettemp(void)
 
int32_t lps25h_get_temperature(void)
 
{
 
	return temp_celsius;
 
}
 
 
 
// Get current pressure in hPa
 
int32_t pressure_getpressure(void)
 
int32_t lps25h_get_pressure(void)
 
{
 
	return pressure_hPa;
 
}
 
 
 
 
inline I2C_HandleTypeDef* pressure_get_i2c_handle(void)
 
inline I2C_HandleTypeDef* lps25h_get_i2c_handle(void)
 
{
 
	return &hi2c1;
 
}
 
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab
Source/main.c
Show inline comments
 
@@ -21,14 +21,18 @@
 
 */
 
 
#include "stm32f0xx_hal.h"
 
 
#include "config.h"
 
#include "error.h"
 
//#include "pressure.h"
 
 
#ifdef LPS25H
 
	#include "lps25h.h"
 
#else
 
#include "bme280.h"
 
#endif
 
#include "gps.h"
 
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
#include "system/watchdog.h"
 
#include "system/uart.h"
 
@@ -46,26 +50,36 @@ int main(void)
 
  gpio_init();
 
  adc_init();
 
  afsk_init();
 
  si446x_init();
 
  si446x_init();
 
  gps_poweron();
 
//  pressure_init();
 
 
  #ifdef LPS25H
 
    lps25h_init();
 
  #else
 
  bme280_init();
 
  #endif
 
 
  // Software timers
 
  uint32_t last_transmission = HAL_GetTick();
 
  uint32_t last_led = HAL_GetTick();
 
 
  while (1)
 
  {
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_transmission > 700)
 
	  {
 
		  gps_update_data(); // Will always return at 1hz rate (default measurement rate)
 
		  //pressure_read();
 
 
		  #ifdef LPS25H
 
		  	  lps25h_read();
 
		  #else
 
		  bme280_update();
 
		  #endif
 
 
		  while(afsk_busy()); // ensure previous message finished
 
		  aprs_send();
 
 
		  last_transmission = HAL_GetTick();
 
	  }
 
0 comments (0 inline, 0 general)