Skip to content

Commit

Permalink
fix tmp117 minus values, set sensors modes, prepering to SIM868 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
bluuu81 committed Mar 2, 2024
1 parent 73b903b commit 8088d08
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 63 deletions.
24 changes: 24 additions & 0 deletions FW/Core/Inc/SIM868.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SIM868.h
*
* Created on: Mar 2, 2024
* Author: bluuu
*/

#include "main.h"

#ifndef INC_SIM868_H_
#define INC_SIM868_H_

#define SIM_ON() HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_SET)
#define SIM_OFF() HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_RESET)

#define GPS_ON() HAL_GPIO_WritePin(SIM_GPS_GPIO_Port, SIM_GPS_Pin, GPIO_PIN_RESET)
#define GPS_OFF() HAL_GPIO_WritePin(SIM_GPS_GPIO_Port, SIM_GPS_Pin, GPIO_PIN_SET)

#define SIM_WDT_READ() HAL_GPIO_ReadPin(SIM_WDT_GPIO_Port, SIM_WDT_Pin)


void SIM_HW_OFF();

#endif /* INC_SIM868_H_ */
2 changes: 2 additions & 0 deletions FW/Core/Inc/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "stm32l4xx_hal.h"
#include "thp_sensors.h"
#include "main.h"
#include "SIM868.h"


#define MIN_OFFSET -10.0f
#define MAX_OFFSET +10.0f
Expand Down
2 changes: 1 addition & 1 deletion FW/Core/Inc/dps368.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ float DPS368_calc_temp(float temp_scaled);
float DPS368_get_temp();
float DPS368_get_press(float temp_scaled);
uint32_t calcBusyTime(uint8_t ovr);
uint16_t dps368_ovr_conf(uint8_t sensor_conf);
uint16_t dps368_ovr_config(uint8_t sensor_conf);
#endif /* INC_DPS368_H_ */
4 changes: 0 additions & 4 deletions FW/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ void ReinitTimer(uint16_t period);
#define Tamp_READ() HAL_GPIO_ReadPin(Tamp_GPIO_Port, Tamp_Pin)

#define BQ_INT_READ() HAL_GPIO_ReadPin(BQ_INT_GPIO_Port, BQ_INT_Pin)
#define SIM_WDT_READ() HAL_GPIO_ReadPin(SIM_WDT_GPIO_Port, SIM_WDT_Pin)

#define GPS_ON() HAL_GPIO_WritePin(SIM_GPS_GPIO_Port, SIM_GPS_Pin, GPIO_PIN_SET)
#define GPS_OFF() HAL_GPIO_WritePin(SIM_GPS_GPIO_Port, SIM_GPS_Pin, GPIO_PIN_RESET)

#define I2C2TCA_RST() HAL_GPIO_WritePin(RST2_GPIO_Port, RST2_Pin, GPIO_PIN_RESET)
#define I2C2TCA_NRST() HAL_GPIO_WritePin(RST2_GPIO_Port, RST2_Pin, GPIO_PIN_SET)
Expand Down
2 changes: 1 addition & 1 deletion FW/Core/Inc/thp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>

#define HW_VER 10
#define FW_VER 4
#define FW_VER 5

extern ADC_HandleTypeDef hadc1;

Expand Down
1 change: 1 addition & 0 deletions FW/Core/Inc/thp_sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void printbinary(uint16_t value);
void printbinaryMSB(uint8_t value);
void setBit(uint8_t* reg, int bitNumber, int value);
void modifyRegister(unsigned char* reg, unsigned char mask, unsigned char value);
uint16_t combine_uint8(uint8_t high, uint8_t low);

void i2c_scan(I2C_HandleTypeDef * i2c, uint8_t addr_min, uint8_t addr_max);
uint8_t i2c_read8(I2C_HandleTypeDef * i2c, uint16_t offset, uint8_t *value, uint8_t addr);
Expand Down
11 changes: 6 additions & 5 deletions FW/Core/Src/EEPROM.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,35 @@ void Load_defaults()
config.batt_alarm = BATT_ALARM_VOLTAGE; // definicja w main.h
config.reset_state = 0;
config.disp_type = TXT;
config.tim_interval = 5;
config.tim_interval = 8;
config.TMP117_use = 1;
config.TMP117_conf = 1;
config.TMP117_t_use = 1;
config.TMP117_t_offset = 0.0f;
config.SHT3_use = 1;
config.SHT3_conf = 0;
config.SHT3_t_use = 1;
config.SHT3_t_use = 0;
config.SHT3_h_use = 1;
config.SHT3_t_offset = 0.0f;
config.SHT3_h_offset = 0.0f;
config.MS8607_use = 1;
config.MS8607_conf = 0;
config.MS8607_conf = 3;
config.MS8607_t_use = 1;
config.MS8607_h_use = 1;
config.MS8607_p_use = 1;
config.MS8607_t_offset = 0.0f;
config.MS8607_h_offset = 0.0f;
config.MS8607_p_offset = 0.0f;
config.BME280_use = 1;
config.BME280_conf = 0;
config.BME280_conf = 10;
config.BME280_t_use = 1;
config.BME280_h_use = 1;
config.BME280_p_use = 1;
config.BME280_t_offset = 0.0f;
config.BME280_h_offset = 0.0f;
config.BME280_p_offset = 0.0f;
config.DPS368_use = 1;
config.DPS368_conf = 0;
config.DPS368_conf = 8;
config.DPS368_t_use = 1;
config.DPS368_p_use = 1;
config.DPS368_t_offset = 0.0f;
Expand All @@ -210,6 +210,7 @@ void EEPROM_Print_config(void)
printf("SHTC3 hum offset: %f \r\n", config.SHT3_h_offset);

printf("MS8607 sensor use %i %i \r\n", config.MS8607_use, MS8607.sensor_use);
printf("MS8607 config %i %i \r\n", config.MS8607_conf, MS8607.sensor_conf);
printf("MS8607 temp meas %i %i \r\n", config.MS8607_t_use, MS8607.temp.use_meas);
printf("MS8607 press meas %i %i \r\n", config.MS8607_p_use, MS8607.press.use_meas);
printf("MS8607 hum meas %i %i \r\n", config.MS8607_h_use, MS8607.hum.use_meas);
Expand Down
13 changes: 13 additions & 0 deletions FW/Core/Src/SIM868.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* SIM868.c
*
* Created on: Mar 2, 2024
* Author: bluuu
*/
#include "SIM868.h"

void SIM_HW_OFF()
{
SIM_OFF();
GPS_OFF();
}
28 changes: 20 additions & 8 deletions FW/Core/Src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ extern uint16_t meas_count;
extern uint8_t meas_cont_mode;

extern uint16_t tmp117_avr;
extern uint8_t dps368_ovr;
extern uint8_t dps368_ovr_conf;
extern uint8_t dps368_ovr_temp;
extern uint8_t dps368_ovr_press;
extern uint8_t sht3_mode;

uint16_t csvcnt;
Expand Down Expand Up @@ -162,6 +164,7 @@ void CLI_proc(char ch)
cliptr = 0;
// Main commands ------------------------------------------------------------------------------
if(find("?")==clibuf+1 || find("help")==clibuf+4) {print_help(); return;}
if(find("status")==clibuf+6) {print_status(); return;}
if(find("i2cscan")==clibuf+7) {i2c_scan(&hi2c2, 0x38, 0xA0); return;}
if(find("clearconfig")==clibuf+11) {printf("config reset to defaults\r\n"); Load_defaults(); return;}
if(find("printconfig")==clibuf+11) {EEPROM_Print_config(); return;}
Expand All @@ -170,6 +173,13 @@ void CLI_proc(char ch)
if(find("setbattalarm")==clibuf+12){getval(clibuf+13, &temp, 0, 15000); config.batt_alarm=temp; printf("Batt alarm:%i",config.batt_alarm); return;};
if(find("setbatscale")==clibuf+11){getFloat(clibuf+12, &tempfloat, -10.0, 10.0); config.bat_scale=tempfloat; printf("Batt scale:%f \r\n",config.bat_scale); return;};

if(find("sim on")==clibuf+6) {SIM_ON(); return;}
if(find("sim off")==clibuf+7) {SIM_OFF(); return;}

if(find("gps on")==clibuf+6) {GPS_ON(); return;}
if(find("gps off")==clibuf+7) {GPS_OFF(); return;}


p = find("set ");
if(p == clibuf+4)
{
Expand Down Expand Up @@ -410,7 +420,7 @@ void CLI_proc(char ch)
if((strstr(clibuf+17, "offset ")))
{
float tmp;
getFloat(clibuf+24, &tmp, MIN_OFFSET, MAX_OFFSET);
getFloat(clibuf+24, &tmp, -500, 500);
config.MS8607_p_offset = tmp;
MS8607.press.offset = tmp;
printf("MS8607 pressure offset %.6f\r\n",tmp);
Expand Down Expand Up @@ -486,7 +496,7 @@ void CLI_proc(char ch)
if((p = find("conf ")))
{
int32_t tmp = -1;
getval(clibuf+16, &tmp, 0, 9);
getval(clibuf+16, &tmp, 0, 10);
config.BME280_conf = tmp;
BME280.sensor_conf = tmp;
bme280_conf_change(tmp);
Expand Down Expand Up @@ -528,7 +538,7 @@ void CLI_proc(char ch)
if((strstr(clibuf+17, "offset ")))
{
float tmp;
getFloat(clibuf+24, &tmp, MIN_OFFSET, MAX_OFFSET);
getFloat(clibuf+24, &tmp, -500, 500);
config.BME280_p_offset = tmp;
BME280.press.offset = tmp;
printf("BME280 pressure offset %.6f\r\n",tmp);
Expand Down Expand Up @@ -603,11 +613,13 @@ void CLI_proc(char ch)
if((p = find("conf ")))
{
int32_t tmp = -1;
getval(clibuf+16, &tmp, 0, 7);
getval(clibuf+16, &tmp, 0, 8);
config.DPS368_conf = tmp;
DPS368.sensor_conf = tmp;
dps368_ovr=dps368_ovr_conf(DPS368.sensor_conf);
DPS368_temp_correct(dps368_ovr);
dps368_ovr_conf=dps368_ovr_config(DPS368.sensor_conf);
dps368_ovr_temp = (uint8_t)(dps368_ovr_conf >> 8);
dps368_ovr_press = (uint8_t)dps368_ovr_conf;
DPS368_temp_correct(dps368_ovr_temp);
printf("DPS368 temperature config %li\r\n",tmp);
Save_config();
}
Expand Down Expand Up @@ -647,7 +659,7 @@ void CLI_proc(char ch)
if((strstr(clibuf+17, "offset ")))
{
float tmp;
getFloat(clibuf+24, &tmp, MIN_OFFSET, MAX_OFFSET);
getFloat(clibuf+24, &tmp, -500, 500);
config.DPS368_p_offset = tmp;
DPS368.press.offset = tmp;
printf("DPS368 pressure offset %.6f\r\n",tmp);
Expand Down
41 changes: 22 additions & 19 deletions FW/Core/Src/dps368.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,36 +462,39 @@ float DPS368_get_press(float temp_scaled)
return pressure;
}

uint16_t dps368_ovr_conf(uint8_t sensor_conf)
uint16_t dps368_ovr_config(uint8_t sensor_conf)
{
switch (sensor_conf) {
case 0:
printf("DPS368 set Oversample x1\r\n");
return DPS_OVERSAMPLE_1;
printf("DPS368 set TEMP & PRESS Oversample x1\r\n");
return combine_uint8(DPS_OVERSAMPLE_1,DPS_OVERSAMPLE_1);
case 1:
printf("DPS368 set Oversample x2\r\n");
return DPS_OVERSAMPLE_2;
printf("DPS368 set TEMP & PRESS Oversample x2\r\n");
return combine_uint8(DPS_OVERSAMPLE_2,DPS_OVERSAMPLE_2);
case 2:
printf("DPS368 set Oversample x4\r\n");
return DPS_OVERSAMPLE_4;
printf("DPS368 set TEMP & PRESS Oversample x4\r\n");
return combine_uint8(DPS_OVERSAMPLE_4,DPS_OVERSAMPLE_4);
case 3:
printf("DPS368 set Oversample x8\r\n");
return DPS_OVERSAMPLE_8;
printf("DPS368 set TEMP & PRESS Oversample x8\r\n");
return combine_uint8(DPS_OVERSAMPLE_8,DPS_OVERSAMPLE_8);
case 4:
printf("DPS368 set Oversample x16\r\n");
return DPS_OVERSAMPLE_16;
printf("DPS368 set TEMP & PRESS Oversample x16\r\n");
return combine_uint8(DPS_OVERSAMPLE_16,DPS_OVERSAMPLE_16);
case 5:
printf("DPS368 set Oversample x32\r\n");
return DPS_OVERSAMPLE_32;
printf("DPS368 set TEMP & PRESS Oversample x32\r\n");
return combine_uint8(DPS_OVERSAMPLE_32,DPS_OVERSAMPLE_32);
case 6:
printf("DPS368 set Oversample x64\r\n");
return DPS_OVERSAMPLE_64;
printf("DPS368 set TEMP & PRESS Oversample x64\r\n");
return combine_uint8(DPS_OVERSAMPLE_64,DPS_OVERSAMPLE_64);
case 7:
printf("DPS368 set Oversample x128\r\n");
return DPS_OVERSAMPLE_128;
printf("DPS368 set TEMP & PRESS Oversample x128\r\n");
return combine_uint8(DPS_OVERSAMPLE_128,DPS_OVERSAMPLE_128);
case 8:
printf("DPS368 set TEMP Oversample x128, PRESS Oversample x4 \r\n");
return combine_uint8(DPS_OVERSAMPLE_128,DPS_OVERSAMPLE_4);

default:
printf("DPS368 set Oversample x1\r\n");
return DPS_OVERSAMPLE_1;
printf("DPS368 set TEMP Oversample x128, PRESS Oversample x4 \r\n");
return combine_uint8(DPS_OVERSAMPLE_128,DPS_OVERSAMPLE_4);
}
}
22 changes: 14 additions & 8 deletions FW/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ uint16_t meas_count = 10;
uint8_t meas_cont_mode = 1;

uint16_t tmp117_avr;
uint8_t dps368_ovr;
volatile uint8_t dps368_ovr_temp;
volatile uint8_t dps368_ovr_press;
volatile uint16_t dps368_ovr_conf;
uint8_t sht3_mode;


Expand Down Expand Up @@ -151,6 +153,7 @@ int main(void)
HAL_UART_RxCpltCallback(&huart1); //CLI
HAL_UART_RxCpltCallback(&huart2); //SIM
check_powerOn();
SIM_HW_OFF();
printf("\r\n\r\n\r\nInitializing ...\r\n");
if (Load_config()==0) {printf("Config loaded OK \r\n");};
charger_state = BQ25798_check();
Expand Down Expand Up @@ -182,10 +185,13 @@ int main(void)

tmp117_avr=tmp117_avr_conf(TMP117.sensor_conf);
// printf("TMP117 conf var %x\r\n", tmp117_avr);
dps368_ovr=dps368_ovr_conf(DPS368.sensor_conf);
printf("DPS368 conf var %x\r\n", dps368_ovr);
dps368_ovr_conf=dps368_ovr_config(DPS368.sensor_conf);
printf("DPS368 conf var %x\r\n", dps368_ovr_conf);
dps368_ovr_temp = (uint8_t)(dps368_ovr_conf >> 8);
dps368_ovr_press = (uint8_t)dps368_ovr_conf;

DPS368_init(FIFO_DIS, INT_NONE);
DPS368_temp_correct(dps368_ovr);
DPS368_temp_correct(dps368_ovr_temp);

sht3_mode=SHT3.sensor_conf;
if(sht3_mode==normal) printf("SHTC3 normal mode\r\n");
Expand Down Expand Up @@ -290,8 +296,8 @@ int main(void)
}
if(DPS368.present){
if(DPS368.sensor_use && (DPS368.temp.use_meas || DPS368.press.use_meas)) {
DPS368_start_meas_temp(dps368_ovr);
meas_time += calcBusyTime(dps368_ovr);
DPS368_start_meas_temp(dps368_ovr_temp);
meas_time += calcBusyTime(dps368_ovr_temp);
if (DPS368.press.use_meas) {
dps368_press = 1;
}
Expand Down Expand Up @@ -372,8 +378,8 @@ int main(void)


if(dps368_press) {
DPS368_start_meas_press(dps368_ovr);
dps_meas_time = calcBusyTime(dps368_ovr);
DPS368_start_meas_press(dps368_ovr_press);
dps_meas_time = calcBusyTime(dps368_ovr_press);
dps368_press = 0;
dps368_press_ready = 1;
}
Expand Down
Loading

0 comments on commit 8088d08

Please sign in to comment.