Skip to content
6 changes: 4 additions & 2 deletions Core/Inc/msb.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef MSB_CENTRAL_H
#define MSB_CENTRAL_H

Expand All @@ -21,7 +20,10 @@ typedef enum {
int8_t msb_init();

#ifdef SENSOR_TEMP
int8_t central_temp_measure(uint16_t *temp, uint16_t *humidity);
/// @brief Measure the temperature and humidity of central MSB SHT30
/// @param out
/// @return error code
int8_t central_temp_measure(float *temp, float *humidity);
#endif

#ifdef SENSOR_TOF
Expand Down
16 changes: 10 additions & 6 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cmsis_os.h"
#include "msb.h"
#include "msb_conf.h"
#include "sht30.h"

#include "stm32f405xx.h"
#include <stdio.h>
Expand Down Expand Up @@ -46,12 +47,12 @@ void vTempMonitor(void *pv_params)
.data = { 0 } };

struct __attribute__((__packed__)) {
uint16_t temp;
uint16_t humidity;
float temp;
float humidity;
} temp_sensor_data;

uint16_t temp_dat = 0;
uint16_t humidity_dat = 0;
float temp_dat = 0;
float humidity_dat = 0;

for (;;) {
if (central_temp_measure(&temp_dat, &humidity_dat)) {
Expand All @@ -62,10 +63,13 @@ void vTempMonitor(void *pv_params)
temp_sensor_data.humidity = humidity_dat;

#ifdef LOG_VERBOSE
printf("Board Temperature:\t%d\r\n", temp_sensor_data.temp);
printf("Board Humidity:\t%d\r\n", temp_sensor_data.humidity);
printf("Board Temperature: %f\n", temp_sensor_data.temp);
printf("Board Humidity:%f\n", temp_sensor_data.humidity);
#endif

printf("Board Temperature: %f\n", temp_sensor_data.temp);
printf("Board Humidity:%f\n", temp_sensor_data.humidity);

endian_swap(&temp_sensor_data.temp,
sizeof(temp_sensor_data.temp));
endian_swap(&temp_sensor_data.humidity,
Expand Down
48 changes: 37 additions & 11 deletions Core/Src/msb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "lsm6dso_reg.h"
#include "main.h"
#include "motion_fx.h"
#include "sht30.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -49,14 +50,42 @@ VL6180xDev_t tof;
uint32_t adc1_buf[3];
#endif

static inline uint8_t sht30_i2c_write(uint8_t *data, uint8_t dev_address,
uint8_t length)
{
return HAL_I2C_Master_Transmit(&hi2c3, dev_address, data, length,
HAL_MAX_DELAY);
}

static inline uint8_t sht30_i2c_read(uint8_t *data, uint16_t command,
uint8_t dev_address, uint8_t length)
{
return HAL_I2C_Mem_Read(&hi2c3, dev_address, command, sizeof(command),
data, length, HAL_MAX_DELAY);
}

// blocking read uses master transmit (in blocking mode)
static inline uint8_t sht30_i2c_blocking_read(uint8_t *data, uint16_t command,
uint8_t dev_address,
uint8_t length)
{
uint8_t command_buffer[2] = { (command & 0xff00u) >> 8u,
command & 0xffu };
// write command to sht30 before reading
sht30_i2c_write(command_buffer, dev_address, sizeof(command_buffer));
HAL_Delay(1); // 1 ms delay to ensure sht30 returns to idle state
return HAL_I2C_Master_Receive(&hi2c3, dev_address, data, length,
HAL_MAX_DELAY);
}

int8_t msb_init()
{
#ifdef SENSOR_TEMP
/* Initialize the Onboard Temperature Sensor */
temp_sensor = (sht30_t){
.i2c_handle = &hi2c3,
};
assert(!sht30_init(&temp_sensor)); /* This is always connected */
assert(!sht30_init(&temp_sensor, (Write_ptr)sht30_i2c_write,
(Read_ptr)sht30_i2c_read,
(Read_ptr)sht30_i2c_blocking_read,
(SHT30_I2C_ADDR))); /* This is always connected */
#endif

#ifdef SENSOR_IMU
Expand Down Expand Up @@ -109,18 +138,15 @@ int8_t msb_init()
}

#ifdef SENSOR_TEMP
/// @brief Measure the temperature and humidity of central MSB SHT30
/// @param out
/// @return error code
int8_t central_temp_measure(uint16_t *temp, uint16_t *humidity)
int8_t central_temp_measure(float *temp, float *humidity)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move docs to header.

{
osStatus_t mut_stat = osMutexAcquire(i2c_mutex, osWaitForever);
if (mut_stat)
return mut_stat;

HAL_StatusTypeDef hal_stat = sht30_get_temp_humid(&temp_sensor);
if (hal_stat)
return hal_stat;
uint8_t status = sht30_get_temp_humid(&temp_sensor);
if (status)
return status;

*temp = temp_sensor.temp;
*humidity = temp_sensor.humidity;
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Embedded-Base
Submodule Embedded-Base updated 85 files
+0 −22 .github/workflows/build_calypso.yml
+14 −0 NetX/inc/u_nx_debug.h
+72 −0 NetX/inc/u_nx_ethernet.h
+79 −0 NetX/src/u_nx_debug.c
+289 −0 NetX/src/u_nx_ethernet.c
+0 −139 cangen/README.md
+0 −49 cangen/archive/CANField.py
+0 −31 cangen/archive/CANMsg.py
+0 −25 cangen/archive/Format.py
+0 −9 cangen/archive/Messages.py
+0 −21 cangen/archive/Result.py
+0 −461 cangen/archive/RustSynth.py
+0 −567 cangen/archive/RustSynthFromJSON.py
+0 −25 cangen/archive/YAMLParser.py
+0 −7 cangen/archive/__init__.py
+0 −130 cangen/archive/jsongen
+0 −18 cangen/archive/templates/decoders.c.j2
+0 −41 cangen/archive/templates/encoders.c.j2
+0 −12 cangen/archive/templates/imports.c.j2
+0 −44 cangen/archive/templates/macros.j2
+0 −28 cangen/archive/templates/routers.c.j2
+0 −3,023 cangen/can-messages/bms.json
+0 −283 cangen/can-messages/calypso_cmd.json
+0 −243 cangen/can-messages/charger.json
+0 −1,302 cangen/can-messages/dti.json
+0 −1,614 cangen/can-messages/mpu.json
+0 −1,186 cangen/can-messages/msb.json
+0 −63 cangen/can-messages/wheel.json
+0 −90 cangen/change_spec.py
+3 −4 dev/Dockerfile
+1,952 −0 dev/renode/can/STMCAN_NER.cs
+219 −0 dev/renode/can/SocketCANBridgeNER.cs
+87 −0 dev/renode/cpus/stm32f103_ner.repl
+227 −0 dev/renode/cpus/stm32f405_ner.repl
+388 −0 dev/renode/i2c/STM32F4_I2C_NER.cs
+269 −0 dev/renode/peripherals/INA226.cs
+98 −0 dev/renode/peripherals/LSM6DSO_IMU_I2C.cs
+1,191 −0 dev/renode/peripherals/LSM6DSO_IMU_NER.cs
+151 −0 dev/renode/peripherals/PCA9539.cs
+556 −0 dev/renode/peripherals/STM32ADCNER.cs
+599 −0 dev/renode/peripherals/STM32DMANER.cs
+91 −0 general/include/as3935.h
+185 −0 general/include/lan8670.h
+510 −0 general/include/lis2mdl_reg.h
+56 −8 general/include/m24c32.h
+19 −24 general/include/sht30.h
+4 −0 general/include/stm32xx_hal.h
+8 −8 general/include/tca9539.h
+178 −0 general/src/as3935.c
+521 −0 general/src/lan8670.c
+1,417 −0 general/src/lis2mdl_reg.c
+41 −48 general/src/m24c32.c
+44 −53 general/src/sht30.c
+7 −7 middleware/include/bitstream.h
+13 −6 middleware/include/c_utils.h
+83 −0 middleware/include/eeprom_directory.h
+25 −0 middleware/include/eeprom_status.h
+0 −57 middleware/include/eepromdirectory.h
+47 −0 middleware/include/m24c32_eeprom_directory.h
+27 −0 middleware/include/serial.h
+2 −1 middleware/include/timer.h
+35 −9 middleware/src/bitstream.c
+88 −0 middleware/src/eeprom_directory.c
+0 −106 middleware/src/eepromdirectory.c
+58 −0 middleware/src/m24c32_eeprom_directory.c
+35 −0 middleware/src/serial.c
+49 −14 ner_environment/build_system/build_system.py
+199 −0 ner_environment/build_system/serial2.py
+2 −0 ner_environment/requirements.txt
+4 −0 platforms/stm32f405/include/stm32xx_hal.h
+5 −2 platforms/stm32f405/src/can.c
+33 −0 platforms/stm32h563/include/fdcan.h
+16 −0 platforms/stm32h563/include/stm32xx_hal.h
+129 −0 platforms/stm32h563/src/fdcan.c
+11 −0 threadX/inc/u_tx_can.h
+59 −0 threadX/inc/u_tx_debug.h
+10 −0 threadX/inc/u_tx_general.h
+29 −0 threadX/inc/u_tx_mutex.h
+40 −0 threadX/inc/u_tx_queues.h
+29 −0 threadX/inc/u_tx_threads.h
+40 −0 threadX/src/u_tx_can.c
+98 −0 threadX/src/u_tx_debug.c
+45 −0 threadX/src/u_tx_mutex.c
+102 −0 threadX/src/u_tx_queues.c
+36 −0 threadX/src/u_tx_threads.c