diff --git a/.cproject b/.cproject index b5647e5..eb88b8f 100644 --- a/.cproject +++ b/.cproject @@ -17,37 +17,37 @@ - diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index aa0cc18..2b28901 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/Debug/src/subdir.mk b/Debug/src/subdir.mk index d3b37c7..c6c381d 100644 --- a/Debug/src/subdir.mk +++ b/Debug/src/subdir.mk @@ -56,7 +56,7 @@ C_DEPS += \ src/%.o: ../src/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/aprs/subdir.mk b/Debug/system/src/aprs/subdir.mk index 540e817..4f5d2f6 100644 --- a/Debug/system/src/aprs/subdir.mk +++ b/Debug/system/src/aprs/subdir.mk @@ -47,7 +47,7 @@ C_DEPS += \ system/src/aprs/%.o: ../system/src/aprs/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/cmsis/subdir.mk b/Debug/system/src/cmsis/subdir.mk index 9700797..765c20a 100644 --- a/Debug/system/src/cmsis/subdir.mk +++ b/Debug/system/src/cmsis/subdir.mk @@ -20,7 +20,7 @@ C_DEPS += \ system/src/cmsis/%.o: ../system/src/cmsis/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/cortexm/subdir.mk b/Debug/system/src/cortexm/subdir.mk index 3482a16..06bdddc 100644 --- a/Debug/system/src/cortexm/subdir.mk +++ b/Debug/system/src/cortexm/subdir.mk @@ -23,7 +23,7 @@ C_DEPS += \ system/src/cortexm/%.o: ../system/src/cortexm/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/diag/subdir.mk b/Debug/system/src/diag/subdir.mk index 809480d..be41b0f 100644 --- a/Debug/system/src/diag/subdir.mk +++ b/Debug/system/src/diag/subdir.mk @@ -20,7 +20,7 @@ C_DEPS += \ system/src/diag/%.o: ../system/src/diag/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/drivers/subdir.mk b/Debug/system/src/drivers/subdir.mk index 7e20b63..942e0f4 100644 --- a/Debug/system/src/drivers/subdir.mk +++ b/Debug/system/src/drivers/subdir.mk @@ -6,6 +6,7 @@ C_SRCS += \ ../system/src/drivers/_dht22.c \ ../system/src/drivers/analog_anemometer.c \ +../system/src/drivers/bma150.c \ ../system/src/drivers/dallas.c \ ../system/src/drivers/dma_helper_functions.c \ ../system/src/drivers/gpio_conf.c \ @@ -18,6 +19,7 @@ C_SRCS += \ OBJS += \ ./system/src/drivers/_dht22.o \ ./system/src/drivers/analog_anemometer.o \ +./system/src/drivers/bma150.o \ ./system/src/drivers/dallas.o \ ./system/src/drivers/dma_helper_functions.o \ ./system/src/drivers/gpio_conf.o \ @@ -30,6 +32,7 @@ OBJS += \ C_DEPS += \ ./system/src/drivers/_dht22.d \ ./system/src/drivers/analog_anemometer.d \ +./system/src/drivers/bma150.d \ ./system/src/drivers/dallas.d \ ./system/src/drivers/dma_helper_functions.d \ ./system/src/drivers/gpio_conf.d \ @@ -44,7 +47,7 @@ C_DEPS += \ system/src/drivers/%.o: ../system/src/drivers/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/newlib/subdir.mk b/Debug/system/src/newlib/subdir.mk index 22144c6..c90f3cb 100644 --- a/Debug/system/src/newlib/subdir.mk +++ b/Debug/system/src/newlib/subdir.mk @@ -43,7 +43,7 @@ system/src/newlib/%.o: ../system/src/newlib/%.cpp system/src/newlib/%.o: ../system/src/newlib/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Debug/system/src/stm32f1-stdperiph/subdir.mk b/Debug/system/src/stm32f1-stdperiph/subdir.mk index 30bcf1e..47f38d2 100644 --- a/Debug/system/src/stm32f1-stdperiph/subdir.mk +++ b/Debug/system/src/stm32f1-stdperiph/subdir.mk @@ -44,7 +44,7 @@ C_DEPS += \ system/src/stm32f1-stdperiph/%.o: ../system/src/stm32f1-stdperiph/%.c @echo 'Building file: $<' @echo 'Invoking: Cross ARM C Compiler' - arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" + arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/include/main.h b/include/main.h index 52907e1..1b30217 100644 --- a/include/main.h +++ b/include/main.h @@ -4,8 +4,8 @@ #include "aprs/ax25.h" #include "drivers/serial.h" -#define SW_VER "DF02" -#define SW_DATE "14062020" +#define SW_VER "DF03" +#define SW_DATE "21062020" #define SYSTICK_TICKS_PER_SECONDS 100 #define SYSTICK_TICKS_PERIOD 10 diff --git a/include/rte_wx.h b/include/rte_wx.h index 3e90714..1deb3d5 100644 --- a/include/rte_wx.h +++ b/include/rte_wx.h @@ -8,6 +8,7 @@ #include "drivers/_dht22.h" #include "drivers/dallas.h" #include "drivers/ms5611.h" +#include "drivers/bma150.h" #include "../umb_master/umb_master.h" #include "../umb_master/umb_qf_t.h" @@ -41,6 +42,8 @@ extern uint16_t rte_wx_average_windspeed; extern uint16_t rte_wx_max_windspeed; extern int16_t rte_wx_average_winddirection; +extern int8_t rte_wx_humidity; + extern uint8_t rte_wx_tx20_excessive_slew_rate; extern dht22Values rte_wx_dht, rte_wx_dht_valid; @@ -48,6 +51,7 @@ extern dht22Values rte_wx_dht, rte_wx_dht_valid; extern dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf; extern dallas_average_t rte_wx_dallas_average; extern ms5611_qf_t rte_wx_ms5611_qf; +extern bma150_qf_t rte_wx_bma150_qf; #ifdef _UMB_MASTER diff --git a/src/main.c b/src/main.c index ec8934b..c44da59 100644 --- a/src/main.c +++ b/src/main.c @@ -37,13 +37,20 @@ #ifdef _METEO #include #include "drivers/dallas.h" -#include "drivers/ms5611.h" #include "drivers/i2c.h" #include "drivers/tx20.h" #include "drivers/analog_anemometer.h" #include "aprs/wx.h" #include "drivers/gpio_conf.h" +#ifdef _SENSOR_MS5611 +#include "drivers/ms5611.h" +#endif + +#ifdef _SENSOR_BMA150 +#include "drivers/bma150.h" +#endif + #ifdef _UMB_MASTER #include "umb_master/umb_master.h" #include "umb_master/umb_channel_pool.h" @@ -364,12 +371,18 @@ int main(int argc, char* argv[]){ // configuring interrupt priorities it_handlers_set_priorities(); -#ifdef _METEO +#if (defined _METEO && defined _SENSOR_MS5611) ms5611_reset(&rte_wx_ms5611_qf); ms5611_read_calibration(SensorCalData, &rte_wx_ms5611_qf); ms5611_trigger_measure(0, 0); #endif +#if (defined _METEO && defined _SENSOR_BMA150) + bma150_reset(&rte_wx_bma150_qf); + bma150_read_calibration(&bma150_data_buffer, &rte_wx_bma150_qf); + bma150_setup(); +#endif + // preparing initial beacon which will be sent to host PC using KISS protocol via UART main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%07.2f%c%c%08.2f%c%c %s", (float)_LAT, _LATNS, _SYMBOL_F, (float)_LON, _LONWE, _SYMBOL_S, _COMMENT); diff --git a/src/rte_wx.c b/src/rte_wx.c index 4b0be7f..0c42e72 100644 --- a/src/rte_wx.c +++ b/src/rte_wx.c @@ -29,12 +29,15 @@ uint16_t rte_wx_average_windspeed = 0; uint16_t rte_wx_max_windspeed = 0; int16_t rte_wx_average_winddirection = 0; +int8_t rte_wx_humidity = 0; + uint8_t rte_wx_tx20_excessive_slew_rate = 0; dht22Values rte_wx_dht, rte_wx_dht_valid; // quality factor inside this structure dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf = DALLAS_QF_UNKNOWN; dallas_average_t rte_wx_dallas_average; ms5611_qf_t rte_wx_ms5611_qf; +bma150_qf_t rte_wx_bma150_qf; #ifdef _UMB_MASTER umb_frame_t rte_wx_umb; diff --git a/src/wx_handler.c b/src/wx_handler.c index 09d876f..897cad6 100644 --- a/src/wx_handler.c +++ b/src/wx_handler.c @@ -41,7 +41,7 @@ void wx_get_all_measurements(void) { int32_t return_value = 0; float pressure_average_sum = 0.0f; -#ifdef _METEO +#if (defined _METEO && defined _SENSOR_MS5611) // quering MS5611 sensor for temperature return_value = ms5611_get_temperature(&rte_wx_temperature_ms, &rte_wx_ms5611_qf); @@ -52,6 +52,53 @@ void wx_get_all_measurements(void) { #endif +#if (defined _METEO && defined _SENSOR_BMA150) + // reading raw values + return_value = bma150_read_raw_data(bma150_data_buffer, &rte_wx_bma150_qf); + + if (return_value == BMA150_OK) { + + // converting raw values to humidity + bma150_get_humidity(&rte_wx_humidity, bma150_data_buffer); + + // converting raw values to temperature + bma150_get_temperature(&rte_wx_temperature_ms_valid, bma150_data_buffer); + + // converting raw values to pressure + bma150_get_pressure(&rte_wx_pressure, bma150_data_buffer); + + { + // add the current pressure into buffer + rte_wx_pressure_history[rte_wx_pressure_it++] = rte_wx_pressure; + + // reseting the average length iterator + j = 0; + + // check if and end of the buffer was reached + if (rte_wx_pressure_it >= PRESSURE_AVERAGE_LN) { + rte_wx_pressure_it = 0; + } + + // calculating the average of pressure measuremenets + for (i = 0; i < PRESSURE_AVERAGE_LN; i++) { + + // skip empty slots in the history to provide proper value even for first wx packet + if (rte_wx_pressure_history[i] < 10.0f) { + continue; + } + + // add to the average + pressure_average_sum += rte_wx_pressure_history[i]; + + // increase the average lenght iterator + j++; + } + + rte_wx_pressure_valid = pressure_average_sum / (float)j; + } + } +#endif + #if defined _METEO || defined _DALLAS_AS_TELEM // quering dallas DS12B20 thermometer for current temperature @@ -113,7 +160,7 @@ void wx_get_all_measurements(void) { wx_inhibit_slew_rate_check = 0; #endif -#ifdef _METEO +#if (defined _METEO) && (defined _SENSOR_MS5611) // quering MS5611 sensor for pressure return_value = ms5611_get_pressure(&rte_wx_pressure, &rte_wx_ms5611_qf); @@ -147,6 +194,9 @@ void wx_get_all_measurements(void) { rte_wx_pressure_valid = pressure_average_sum / (float)j; } +#endif + +#ifdef _METEO // if humidity sensor is idle trigger the communiction & measuremenets if (dht22State == DHT22_STATE_DONE || dht22State == DHT22_STATE_TIMEOUT) dht22State = DHT22_STATE_IDLE; diff --git a/system/include/drivers/bma150.h b/system/include/drivers/bma150.h new file mode 100644 index 0000000..76aa12c --- /dev/null +++ b/system/include/drivers/bma150.h @@ -0,0 +1,38 @@ +/* + * bma150.h + * + * Created on: 21.06.2020 + * Author: mateusz + */ + +#ifndef INCLUDE_DRIVERS_BMA150_H_ +#define INCLUDE_DRIVERS_BMA150_H_ + +#include "stdint.h" + +#define BMA150_OK 0 +#define BMA150_SENSOR_NOT_RESPONDING -1 +#define BMA150_SENSOR_NOT_AVALIABLE -2 + +#define BMA150_LN_CALIBRATION 41 +#define BMA150_LN_RAW_DATA 8 + +typedef enum bma150_qf { + BMA150_QF_FULL, + BMA150_QF_NOT_AVAILABLE +}bma150_qf_t; + +extern uint8_t bma150_data_buffer[BMA150_LN_CALIBRATION + 1]; +extern uint8_t bma150_calibration_data[BMA150_LN_RAW_DATA + 1]; + +int32_t bma150_reset(bma150_qf_t* qf); +int32_t bma150_setup(void); +int32_t bma150_read_calibration(uint8_t* calibration, bma150_qf_t* qf); +int32_t bma150_read_raw_data(uint8_t* raw_data, bma150_qf_t* qf); + +int32_t bma150_get_pressure(float* out, uint8_t* raw_data); +int32_t bma150_get_temperature(float* out, uint8_t* raw_data); +int32_t bma150_get_humidity(int8_t* out, uint8_t* raw_data); + + +#endif /* INCLUDE_DRIVERS_BMA150_H_ */ diff --git a/system/include/drivers/i2c.h b/system/include/drivers/i2c.h index c92856b..800a02b 100644 --- a/system/include/drivers/i2c.h +++ b/system/include/drivers/i2c.h @@ -16,8 +16,8 @@ typedef enum i2c_state { }i2c_state_t; void i2cConfigure(void); -int i2cSendData(int addr, int* data, int null); -int i2cReceiveData(int addr, int* data, int num); +int i2c_send_data(int addr, uint8_t* data, int null); +int i2c_receive_data(int addr, int num); void i2cIrqHandler(void); void i2cErrIrqHandler(void); void i2cVariableReset(void); diff --git a/system/src/drivers/bma150.c b/system/src/drivers/bma150.c new file mode 100644 index 0000000..94766ea --- /dev/null +++ b/system/src/drivers/bma150.c @@ -0,0 +1,236 @@ +/* + * bma150.c + * + * Created on: 21.06.2020 + * Author: mateusz + */ + + +#include "../drivers/bma150.h" +#include "../drivers/i2c.h" + +#include + +#define RESET_MAGIC_WORD 0xB6 + +#define TX_ADDR 0xEC // 11101100 +#define RX_ADDR 0xED // 11101101 + +#define MODE 3 // Normal aka 'cyclic' mode +#define FILTER_COEFFICIENT_LN 16 +#define HUMIDITY_OVERSAMPLING 4 // oversampling x8 +#define PRESSURE_OVERSAMPLING 3 // oversampling x4 +#define TEMPERATURE_OVERSAMPLING 3 // oversampling x4 +#define STANDBY_TIME 5 // one second + +#define CTRL_HUM_ADDR 0xF2 +#define STATUS_ADDR 0xF3 +#define CTRL_MEAS_ADDR 0xF4 +#define CONFIG_ADDR 0xF5 +#define RESET_ADDR 0xE0 + +#define CALIB00_ADDR 0x88 +#define CALIB00_READ_LN 0x1A + +#define CALIB26_ADDR 0xE1 +#define CALIB26_READ_LN 0x10 + +uint8_t bma150_sensor_avaliable = 0; + +uint8_t bma150_data_buffer[BMA150_LN_CALIBRATION + 1]; +uint8_t bma150_calibration_data[BMA150_LN_RAW_DATA + 1]; + +/** + * This function resets the BMA150 sensor to initial state. After it is called + * the sensor must be reconfigured once again. + */ +int32_t bma150_reset(bma150_qf_t* qf) { + int32_t out = BMA150_OK; + + // i2c transmit buffer + uint8_t tx_buf[] = {RESET_ADDR, RESET_MAGIC_WORD, 0}; + + // Send a data to sensor + i2c_send_data(TX_ADDR, tx_buf, 0); + + // Wait until the transmission will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // If reset was successfull enable a driver + if (i2c_state == I2C_IDLE) { + // Enable sensor comms + bma150_sensor_avaliable = 1; + + // wait for sensor reset + delay_fixed(50); + + } + else { + // Set Quality Factor to unavaliable + *qf = BMA150_QF_NOT_AVAILABLE; + + // Return with keeping 'ms5611_sensor_abaliable' set to zero which will + // disable comms + return BMA150_SENSOR_NOT_RESPONDING; + } + + return out; +} + +int32_t bma150_setup(void) { + int32_t out = BMA150_OK; + + // local variables to represent the data wrote to configuration registers + uint8_t ctrl_meas = 0; + uint8_t ctrl_hum = 0; + uint8_t config = 0; + + if (bma150_sensor_avaliable == 0) { + return BMA150_SENSOR_NOT_AVALIABLE; + } + + // setting humidity measurement configutation + ctrl_hum = HUMIDITY_OVERSAMPLING; + + // set mode, and oversampling for humidity and temperature + ctrl_meas = MODE | (PRESSURE_OVERSAMPLING << 2) | (TEMPERATURE_OVERSAMPLING << 5); + + // set standby time and filter lenght + config = (FILTER_COEFFICIENT_LN << 2) | (STANDBY_TIME << 5); + + // transmit buffer + uint8_t tx_buff[] = {CTRL_HUM_ADDR, ctrl_hum, CTRL_MEAS_ADDR, ctrl_meas, CONFIG_ADDR, config, 0}; + + // Send a data to sensor + i2c_send_data(TX_ADDR, tx_buff, 0); + + // Wait until the transmission will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // If reset was successfull enable a driver + if (i2c_state == I2C_IDLE) { + ; + } + else { + out = BMA150_SENSOR_NOT_RESPONDING; + } + + return out; +} + +int32_t bma150_read_calibration(uint8_t* calibration, bma150_qf_t* qf) { + int32_t out = BMA150_OK; + + if (bma150_sensor_avaliable == 0) { + return BMA150_SENSOR_NOT_AVALIABLE; + } + + // transmit buffer + uint8_t tx_buf[] = {CALIB00_ADDR, 0, 0}; + + // Send a data to sensor + i2c_send_data(TX_ADDR, tx_buf, 0); + + // Wait until the transmission will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // check if transmission was successfull + if (i2c_state == I2C_IDLE) { + ; + } + else { + *qf = BMA150_QF_NOT_AVAILABLE; + + return BMA150_SENSOR_NOT_RESPONDING; + } + + // clearing receive buffer + memset(calibration, 0x00, BMA150_LN_CALIBRATION + 1); + + // reading first segment of calibration data + i2c_receive_data(RX_ADDR, CALIB00_READ_LN); + + // Wait until receiving will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // check if receive was successfull + if (i2c_state == I2C_IDLE) { + ; + } + else { + *qf = BMA150_QF_NOT_AVAILABLE; + + return BMA150_SENSOR_NOT_RESPONDING; + } + + // copying read data + memcpy(calibration, (uint8_t*)i2c_rx_data, CALIB00_READ_LN); + + // preparing the buffer to receive second segment of calibration data + tx_buf[0] = CALIB26_ADDR; + + // Send the second request to the sensor + i2c_send_data(TX_ADDR, tx_buf, 0); + + // Wait until the transmission will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // check if transmission was successfull + if (i2c_state == I2C_IDLE) { + ; + } + else { + *qf = BMA150_QF_NOT_AVAILABLE; + + return BMA150_SENSOR_NOT_RESPONDING; + } + + // reading second segment of calibration data + i2c_receive_data(RX_ADDR, CALIB26_READ_LN); + + // Wait until receiving will finish or fail (due to timeout or any other error) + while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR); + + // check if receive was successfull + if (i2c_state == I2C_IDLE) { + ; + } + else { + *qf = BMA150_QF_NOT_AVAILABLE; + + return BMA150_SENSOR_NOT_RESPONDING; + } + + // copying read data + memcpy(calibration + CALIB00_READ_LN, (uint8_t*)i2c_rx_data, CALIB26_READ_LN); + + return out; +} + +int32_t bma150_read_raw_data(uint8_t* raw_data, bma150_qf_t* qf) { + int32_t out = BMA150_OK; + + if (bma150_sensor_avaliable == 0) { + return BMA150_SENSOR_NOT_AVALIABLE; + } + + return out; +} + +int32_t bma150_get_pressure(float* out, uint8_t* raw_data) { + int32_t ret = BMA150_OK; + + return ret; +} + +int32_t bma150_get_temperature(float* out, uint8_t* raw_data) { + int32_t ret = BMA150_OK; + + return ret; +} + +int32_t bma150_get_humidity(int8_t* out, uint8_t* raw_data) { + int32_t ret = BMA150_OK; + + return ret; +} diff --git a/system/src/drivers/i2c.c b/system/src/drivers/i2c.c index d9166de..d9912e0 100644 --- a/system/src/drivers/i2c.c +++ b/system/src/drivers/i2c.c @@ -96,7 +96,7 @@ int i2cReinit() { return 0; } -int i2cSendData(int addr, int* data, int null) { +int i2c_send_data(int addr, uint8_t* data, int null) { int i; for (i = 0; (i<32 && *(data+i) != '\0'); i++) i2c_tx_data[i]=data[i]; @@ -120,7 +120,7 @@ int i2cSendData(int addr, int* data, int null) { return 0; } -int i2cReceiveData(int addr, int* data, int num) { +int i2c_receive_data(int addr, int num) { i2c_rx_bytes_number = num; i2c_remote_addr = addr; i2c_trx_data_counter = 0; @@ -178,7 +178,7 @@ void i2cIrqHandler(void) { if ((I2C1->SR1 & I2C_SR1_TXE) == I2C_SR1_TXE && i2c_txing == 1) { // If I2C is in transmission mode and the data buffer is busy // put the next in the data register EV_8_1 - I2C1->DR = i2c_tx_data[0]; // TODO: This is probably a bug? + I2C1->DR = i2c_tx_data[i2c_trx_data_counter]; i2c_trx_data_counter++; } if (i2c_trx_data_counter == i2c_tx_queue_len && i2c_txing == 1) { diff --git a/system/src/drivers/ms5611.c b/system/src/drivers/ms5611.c index 31c569c..5e116bb 100644 --- a/system/src/drivers/ms5611.c +++ b/system/src/drivers/ms5611.c @@ -1,6 +1,7 @@ #include "drivers/ms5611.h" #include "drivers/i2c.h" #include "../include/delay.h" +#include "station_config.h" #include "rte_wx.h" @@ -16,6 +17,8 @@ char state; // zmienna sygnalizuj�ca przebieg pomiaru.. #define TX_ADDR 0xEE #define RX_ADDR 0xEF +#ifdef _SENSOR_MS5611 + // An array to store Calibration data int32_t SensorCalData[8]; double SensorDT = 0.0; @@ -377,3 +380,5 @@ float CalcQNHFromQFE(float qfe, float alti, float temp) { return qnh; } + +#endif