Compare commits

...

4 Commits

Author SHA1 Message Date
jh.chun 736a3f2c9a Ver119 업데이트: TMP235 온도 센서 → IMU register direct read 전면 대체 2026-06-15 12:27:58 +09:00
jh.chun 4cd5931e2a TMP235 온도 측정 경로 정리
- mst? 온도 응답을 IMU register direct read로 대체
- go_temp/TMP235 legacy 경로 및 빌드 대상 제거
- info_temp 전역 정의를 IMU 모듈로 이동
- TMP235 드라이버는 deprecated reference로 표시
2026-06-15 12:24:06 +09:00
jh.chun 29989054c0 개별 온도 커맨드 mst? 응답 시 TMP235 온도 센서를 IMU register direct read로 대체
- IMU 온도 read 실패 시 rso:ffff 응답
2026-06-15 11:55:03 +09:00
jh.chun 83c0050bf4 FW Ver history 2026-06-15 11:53:01 +09:00
12 changed files with 180 additions and 249 deletions
@@ -46,7 +46,6 @@ extern uint8_t resetCount;
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
extern void battery_level_meas(void); extern void battery_level_meas(void);
extern void pressure_all_level_meas(void); extern void pressure_all_level_meas(void);
extern void tmp235_voltage_level_meas(void);
extern int imu_read_direct(void); extern int imu_read_direct(void);
extern int imu_read_temperature_x100(uint16_t *temp_x100, float *temp_c); extern int imu_read_temperature_x100(uint16_t *temp_x100, float *temp_c);
extern int imu_fifo_capture_start(void); extern int imu_fifo_capture_start(void);
@@ -66,7 +65,6 @@ extern bool motion_raw_data_enabled;
extern volatile uint16_t info_batt; extern volatile uint16_t info_batt;
extern volatile uint16_t info_temp; extern volatile uint16_t info_temp;
extern volatile uint16_t info_imu[6]; extern volatile uint16_t info_imu[6];
extern volatile bool tmp235_saadc_done;
extern volatile bool battery_saadc_done; extern volatile bool battery_saadc_done;
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
@@ -2,14 +2,13 @@
* cmd_sensor.c - Sensor measurement handlers * cmd_sensor.c - Sensor measurement handlers
* *
* msn? -> rsn: battery ADC measurement * msn? -> rsn: battery ADC measurement
* mso? -> rso: TMP235 temperature reading * mst? -> rso: IMU die temperature reading
* msp? -> rsp: IMU 6-axis single read * msp? -> rsp: IMU 6-axis single read
* all_sensors() bulk-measurement helper used by the mbb? handler * all_sensors() bulk-measurement helper used by the mbb? handler
*============================================================================*/ *============================================================================*/
#include "cmd_common.h" #include "cmd_common.h"
#include "cmd_sensor.h" #include "cmd_sensor.h"
#include "dr_piezo.h"
/*============================================================================== /*==============================================================================
* msn? -> rsn: Battery level ADC measurement * msn? -> rsn: Battery level ADC measurement
@@ -25,34 +24,23 @@ int Cmd_msn(const ParsedCmd *cmd)
} }
/*============================================================================== /*==============================================================================
* mst? -> rso: Temperature with piezo power cycle * mst? -> rso: IMU die temperature
* *
* Request: [TAG 4B "mst?"] [CRC 2B] * Request: [TAG 4B "mst?"] [CRC 2B]
* Response: [TAG 4B "rso:"] [temp_x100 2B BE] [CRC 2B] * Response: [TAG 4B "rso:"] [temp_x100 2B BE] [CRC 2B]
*
* TMP235 shares the piezo TX/RX power rail. This command handles the full
* sequence: power ON -> measure -> power OFF, so the caller doesn't need
* to send mpa?/mpb? separately.
* Response is sent from the TMP235 SAADC callback (tmp235_voltage_handler).
*============================================================================*/ *============================================================================*/
int Cmd_mst(const ParsedCmd *cmd) int Cmd_mst(const ParsedCmd *cmd)
{ {
uint32_t timeout_cnt; uint16_t imu_temp_x100 = 0xFFFF;
(void)cmd; (void)cmd;
if (!dr_piezo_is_power_on()) if (imu_read_temperature_x100(&imu_temp_x100, NULL) != 0)
{ {
dr_piezo_power_on(); imu_temp_x100 = 0xFFFF;
} }
tmp235_saadc_done = false; single_format_data(ble_bin_buffer, "rso:", imu_temp_x100);
tmp235_voltage_level_meas(); dr_binary_tx_safe(ble_bin_buffer, 3);
for (timeout_cnt = 0; !tmp235_saadc_done && timeout_cnt < 100; timeout_cnt++)
{
dr_sd_delay_ms(1);
}
dr_piezo_power_off();
return 1; return 1;
} }
@@ -7,7 +7,7 @@
#include "parser.h" #include "parser.h"
int Cmd_msn(const ParsedCmd *cmd); /* msn? -> rsn: battery ADC measurement */ int Cmd_msn(const ParsedCmd *cmd); /* msn? -> rsn: battery ADC measurement */
int Cmd_mst(const ParsedCmd *cmd); /* mst? -> rso: TMP235 with piezo power cycle */ int Cmd_mst(const ParsedCmd *cmd); /* mst? -> rso: IMU die temperature */
int Cmd_msp(const ParsedCmd *cmd); /* msp? -> rsp: IMU 6-axis single read */ int Cmd_msp(const ParsedCmd *cmd); /* msp? -> rsp: IMU 6-axis single read */
/* Helper for the mbb? handler: sequentially measures battery / IMU / temperature, then emits a single rbb: response. /* Helper for the mbb? handler: sequentially measures battery / IMU / temperature, then emits a single rbb: response.
* Called from Cmd_mbb() in cmd_piezo.c. */ * Called from Cmd_mbb() in cmd_piezo.c. */
@@ -12,7 +12,7 @@
* [Hardware Configuration] * [Hardware Configuration]
* - MCU: nRF52840 (SoftDevice S140 v7.x) * - MCU: nRF52840 (SoftDevice S140 v7.x)
* - IMU: ICM42670P 6-axis accel/gyro (I2C, 0x68) * - IMU: ICM42670P 6-axis accel/gyro (I2C, 0x68)
* - Temperature: TMP235-Q1 analog sensor (SAADC AIN3) * - Temperature: IMU register direct read
* - Battery: voltage divider (SAADC AIN2, 1/3 prescale) * - Battery: voltage divider (SAADC AIN2, 1/3 prescale)
* - Power: POWER_HOLD(P0.8) self-latch circuit, POWER_BUTTON(P1.8) input * - Power: POWER_HOLD(P0.8) self-latch circuit, POWER_BUTTON(P1.8) input
* *
@@ -94,7 +94,6 @@
#include "app_raw_main.h" /* Sensor raw data processing module */ #include "app_raw_main.h" /* Sensor raw data processing module */
#include "main_timer.h" /* Main event loop timer (10ms period) */ #include "main_timer.h" /* Main event loop timer (10ms period) */
#include "power_control.h" /* Power sequence control (ON/OFF/sleep) */ #include "power_control.h" /* Power sequence control (ON/OFF/sleep) */
#include "tmp235_q1.h" /* TMP235-Q1 temperature sensor driver */
#include "fds.h" /* Flash Data Storage (non-volatile config) */ #include "fds.h" /* Flash Data Storage (non-volatile config) */
#include "battery_saadc.h" /* Battery voltage measurement (SAADC) */ #include "battery_saadc.h" /* Battery voltage measurement (SAADC) */
@@ -45,8 +45,12 @@
* : rim: packet format and FIFO sample cap/filter options (app_raw). * : rim: packet format and FIFO sample cap/filter options (app_raw).
* - VBTFW0116 260522 jhChun : Expanded BLE TX pending slots from 1 8 to reduce ADC data packet loss when the TX queue is full * - VBTFW0116 260522 jhChun : Expanded BLE TX pending slots from 1 8 to reduce ADC data packet loss when the TX queue is full
* - VBTFW0117 260527 jhChun : Prevent battery/temperature safety checks from powering off piezo during MAA capture, and lock BLE PHY to 1M. * - VBTFW0117 260527 jhChun : Prevent battery/temperature safety checks from powering off piezo during MAA capture, and lock BLE PHY to 1M.
* - VBTFW0118 260601 jhChun
* : Added channel information(2B) to the ADC raw data response packet (reb:).
* : Replaced TMP235 temperature with IMU register direct-read temperature in the rbb: response.
* - VBTFW0119 260615 jhChun : Replaced all TMP235 temperature paths with IMU register direct-read temperature and removed legacy TMP235 build references.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#define FIRMWARE_VERSION "VBTFW0118" #define FIRMWARE_VERSION "VBTFW0119"
/*============================================================================== /*==============================================================================
* Data Length Constants * Data Length Constants
@@ -27,7 +27,6 @@
#include "app_timer.h" #include "app_timer.h"
#include "battery_saadc.h" #include "battery_saadc.h"
#include "main_timer.h" #include "main_timer.h"
#include "tmp235_q1.h"
#include "app_raw.h" #include "app_raw.h"
#include "dr_piezo.h" #include "dr_piezo.h"
#include "debug_print.h" #include "debug_print.h"
@@ -60,9 +59,6 @@ APP_TIMER_DEF(m_battery_loop_timer_id);
/* Low-battery check flag — set by battery_loop, consumed by handler */ /* Low-battery check flag — set by battery_loop, consumed by handler */
bool low_battery_check = false; bool low_battery_check = false;
/* Safety check mode flag — legacy TMP235 path */
bool safety_check_mode = false;
/* SAADC callback completion flag — used by all_sensors() to wait */ /* SAADC callback completion flag — used by all_sensors() to wait */
volatile bool battery_saadc_done = false; volatile bool battery_saadc_done = false;
@@ -85,7 +81,6 @@ extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN];
volatile uint16_t info_batt; volatile uint16_t info_batt;
/* info4 sequential measurement control flags */ /* info4 sequential measurement control flags */
extern bool go_temp;
extern bool go_batt; extern bool go_batt;
extern bool motion_raw_data_enabled; extern bool motion_raw_data_enabled;
@@ -94,7 +89,7 @@ extern bool motion_data_once;
extern bool maa_async_is_busy(void); extern bool maa_async_is_busy(void);
/*============================================================================== /*==============================================================================
* safety_check_complete - Called by tmp235 handler after temperature measurement * safety_check_complete - Called after IMU die temperature measurement
* *
* Checks both battery voltage and temperature against thresholds. * Checks both battery voltage and temperature against thresholds.
* 5 consecutive readings exceeding either threshold triggers power OFF. * 5 consecutive readings exceeding either threshold triggers power OFF.
@@ -168,7 +163,7 @@ void battery_event_handler(nrf_drv_saadc_evt_t const * p_event)
register_val = p_event->data.done.p_buffer[0]; register_val = p_event->data.done.p_buffer[0];
/* Release SAADC — shared with temperature / pressure ADC */ /* Release SAADC — shared with pressure ADC */
nrf_drv_saadc_channel_uninit(0); nrf_drv_saadc_channel_uninit(0);
nrf_drv_saadc_uninit(); nrf_drv_saadc_uninit();
@@ -25,9 +25,6 @@
/* SAADC callback completion flag (used by all_sensors() to wait) */ /* SAADC callback completion flag (used by all_sensors() to wait) */
extern volatile bool battery_saadc_done; extern volatile bool battery_saadc_done;
/* Safety check mode flag — legacy TMP235 path */
extern bool safety_check_mode;
/* Called when safety check temperature measurement completes */ /* Called when safety check temperature measurement completes */
void safety_check_complete(float temp_c); void safety_check_complete(float temp_c);
@@ -93,7 +93,7 @@ extern which_cmd_t cmd_type_t; /* Current command source (
uint16_t ssp_data[6]={0,}; /* 6-axis data array for BLE (accel XYZ + gyro XYZ) */ uint16_t ssp_data[6]={0,}; /* 6-axis data array for BLE (accel XYZ + gyro XYZ) */
extern bool info4; /* info4 mode flag (set by cmd_parse) */ extern bool info4; /* info4 mode flag (set by cmd_parse) */
volatile uint16_t info_imu[6]; /* Global array storing IMU data in info4 mode */ volatile uint16_t info_imu[6]; /* Global array storing IMU data in info4 mode */
extern volatile uint16_t info_temp; /* Global temperature cache (deg C x 100) */ volatile uint16_t info_temp; /* Global temperature cache (deg C x 100) */
/* -------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------
* static function declaration * static function declaration
@@ -1,6 +1,9 @@
/*============================================================================== /*==============================================================================
* tmp235_q1.c - TMP235-Q1 analogue temperature sensor driver * tmp235_q1.c - TMP235-Q1 analogue temperature sensor driver
* *
* Deprecated: temperature measurement has been replaced by IMU register direct read paths.
* This file is kept only as a legacy reference and is not built.
*
* Reads the TMP235-Q1 analogue output via SAADC AIN3 and converts to deg C. * Reads the TMP235-Q1 analogue output via SAADC AIN3 and converts to deg C.
* *
* Temperature conversion (piecewise linear, per datasheet): * Temperature conversion (piecewise linear, per datasheet):
@@ -408,11 +408,6 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\system\power\power_control.c</FilePath> <FilePath>..\..\..\system\power\power_control.c</FilePath>
</File> </File>
<File>
<FileName>tmp235_q1.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\measurement\temperature\tmp235_q1.c</FilePath>
</File>
<File> <File>
<FileName>fstorage.c</FileName> <FileName>fstorage.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -4616,11 +4611,6 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\system\power\power_control.c</FilePath> <FilePath>..\..\..\system\power\power_control.c</FilePath>
</File> </File>
<File>
<FileName>tmp235_q1.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\measurement\temperature\tmp235_q1.c</FilePath>
</File>
<File> <File>
<FileName>fstorage.c</FileName> <FileName>fstorage.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -14,15 +14,10 @@
* - motion_data_once == true: one-shot read (after HW I2C init) * - motion_data_once == true: one-shot read (after HW I2C init)
* - motion_data_once == false: continuous read (when not waiting for BLE TX) * - motion_data_once == false: continuous read (when not waiting for BLE TX)
* go_batt -> Battery voltage measurement (battery_level_meas) * go_batt -> Battery voltage measurement (battery_level_meas)
* go_temp -> Temperature measurement (tmp235_voltage_level_meas)
* go_device_power_off -> Device power OFF (device_power_off) * go_device_power_off -> Device power OFF (device_power_off)
* go_sleep_mode_enter -> Enter sleep mode (sleep_mode_enter) * go_sleep_mode_enter -> Enter sleep mode (sleep_mode_enter)
* go_NVIC_SystemReset -> NVIC system reset * go_NVIC_SystemReset -> NVIC system reset
* *
* [info4 mode measurement order]
* IMU continuous read -> go_batt (battery) -> go_temp (temp) -> motion_data_once (IMU one-shot)
* After temperature measurement, motion_data_once=true to return to IMU.
*
* [Timer settings] * [Timer settings]
* - Normal mode: 10ms interval (MAIN_LOOP_INTERVAL) * - Normal mode: 10ms interval (MAIN_LOOP_INTERVAL)
* - FEATURE_DETAIL_VALUE_FULL mode: 80ms interval (for detail printout) * - FEATURE_DETAIL_VALUE_FULL mode: 80ms interval (for detail printout)
@@ -53,7 +48,6 @@
#include "main.h" #include "main.h"
#include "app_raw_main.h" #include "app_raw_main.h"
#include "main_timer.h" #include "main_timer.h"
#include "tmp235_q1.h"
//#include "fstorage.h" //#include "fstorage.h"
#include "power_control.h" #include "power_control.h"
#include "main.h" /* 2026-03-17: cmd_parse.h removed, use main.h */ #include "main.h" /* 2026-03-17: cmd_parse.h removed, use main.h */
@@ -83,7 +77,6 @@ extern which_cmd_t cmd_type_t;
/* Event flags (set by external modules, processed in main_loop) */ /* Event flags (set by external modules, processed in main_loop) */
/* ========================================================================== */ /* ========================================================================== */
bool go_batt= false; /* Battery measurement request flag */ bool go_batt= false; /* Battery measurement request flag */
bool go_temp= false; /* Temperature measurement request flag */
bool go_device_power_off = false; /* Device power OFF request flag */ bool go_device_power_off = false; /* Device power OFF request flag */
bool go_sleep_mode_enter = false; /* Sleep mode entry request flag */ bool go_sleep_mode_enter = false; /* Sleep mode entry request flag */
bool go_NVIC_SystemReset = false; /* System reset request flag */ bool go_NVIC_SystemReset = false; /* System reset request flag */
@@ -101,10 +94,9 @@ bool motion_data_once = false; /* IMU one-shot read mode (true: read on
* [Processing priority] (checked in code order) * [Processing priority] (checked in code order)
* 1. IMU motion data (motion_raw_data_enabled) * 1. IMU motion data (motion_raw_data_enabled)
* 2. Battery measurement (go_batt) * 2. Battery measurement (go_batt)
* 3. Temperature measurement (go_temp) * 3. Power OFF (go_device_power_off)
* 4. Power OFF (go_device_power_off) * 4. Sleep mode (go_sleep_mode_enter)
* 5. Sleep mode (go_sleep_mode_enter) * 5. System reset (go_NVIC_SystemReset)
* 6. System reset (go_NVIC_SystemReset)
*/ */
void main_loop(void * p_context) /* For x ms */ void main_loop(void * p_context) /* For x ms */
{ {
@@ -192,34 +184,12 @@ void main_loop(void * p_context) /* For x ms */
DBG_PRINTF("IMU BATT\r\n"); DBG_PRINTF("IMU BATT\r\n");
main_timer_stop(); /* Stop timer */ main_timer_stop(); /* Stop timer */
go_batt = false; /* Consume flag (one-shot) */ go_batt = false; /* Consume flag (one-shot) */
// go_temp = true;
battery_level_meas(); /* Measure battery voltage via SAADC */ battery_level_meas(); /* Measure battery voltage via SAADC */
// nrf_delay_ms(20); // nrf_delay_ms(20);
// m48_adc_start_init(); // m48_adc_start_init();
// main_timer_start(); // main_timer_start();
} }
/* ---- Temperature measurement ---- */
/*
* If go_temp is true, measure temperature via TMP235-Q1 sensor.
* Called after battery measurement in info4 mode.
* After completion, sets motion_data_once=true so the next IMU read
* uses one-shot mode (with HW I2C re-init).
*/
if (go_temp == true)
{
DBG_PRINTF("IMU Temp\r\n");
main_timer_stop(); /* Stop timer */
// go_batt = false;
go_temp = false; /* Consume flag (one-shot) */
motion_data_once = true; /* Switch next IMU read to one-shot mode */
tmp235_voltage_level_meas(); /* Measure TMP235-Q1 temperature sensor voltage */
// motion_raw_data_enabled = true;
// main_timer_start();
}
/* ---- System control event handling ---- */ /* ---- System control event handling ---- */
/* Device power OFF handling */ /* Device power OFF handling */
@@ -285,4 +255,3 @@ void main_timer_init(void)
{ {
APP_ERROR_CHECK(app_timer_create(&m_main_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, main_loop)); APP_ERROR_CHECK(app_timer_create(&m_main_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, main_loop));
} }