1、STWINKT1B上有一个SD卡接口可用于电池供电的时候将数据方便的保存到存储卡里面,这里我们就可以把STWINKT1B方便的用于各种场景下数据记录。
TF卡数据接口如下
TF卡使用SDIO进口进行通信,能够进行高速的数据读写。文件系统使用开源的FATFS。
- void DATALOG_SD_Init(void)
- {
- BSP_SD_Detect_Init();
- if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
- {
- /* Register the file system object to the FatFs module */
- if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
- {
- /* FatFs Initialization Error */
- }
- }
- }
再对TF卡初始化完成之后,创建一个csv文件用于存储各个传感器的数据
- uint8_t DATALOG_SD_Log_Enable(void)
- {
- static uint16_t sdcard_file_counter = 0;
- char header[] = "T [ms],AccX [mg],AccY [mg],AccZ [mg],GyroX [mdps],GyroY [mdps],GyroZ [mdps],MagX [mgauss],MagY [mgauss],MagZ [mgauss],P [mB],T [degrees],H [%]\r\n";
- uint32_t byteswritten; /* written byte count */
- char file_name[30] = {0};
-
- sprintf(file_name, "%s%.3d%s", "ind", sdcard_file_counter, ".csv");
-
- sdcard_file_counter++;
- HAL_Delay(100);
- if(f_open(&MyFile, (char const*)file_name, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
- {
- sdcard_file_counter--;
- return 0;
- }
-
- if(f_write(&MyFile, (const void*)&header, sizeof(header)-1, (void *)&byteswritten) != FR_OK)
- {
- return 0;
- }
-
- return 1;
-
- }
然后是对各个传感器进行数据读取
- int32_t getSensorsData( T_SensorsData *mptr)
- {
- int32_t ret = BSP_ERROR_NONE;
- mptr->ms_counter = HAL_GetTick();
-
- #ifdef USE_IIS2DH
-
- if ( BSP_MOTION_SENSOR_GetAxes( IIS2DH_0, MOTION_ACCELERO, &mptr->acc ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->acc.x = 0;
- mptr->acc.y = 0;
- mptr->acc.z = 0;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
- #elif USE_ISM330DHCX
-
- if ( BSP_MOTION_SENSOR_GetAxes( ISM330DHCX_0, MOTION_ACCELERO, &mptr->acc ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->acc.x = 0;
- mptr->acc.y = 0;
- mptr->acc.z = 0;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- #endif
- if ( BSP_MOTION_SENSOR_GetAxes(ISM330DHCX_0, MOTION_GYRO, &mptr->gyro ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->gyro.x = 0;
- mptr->gyro.y = 0;
- mptr->gyro.z = 0;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- if ( BSP_MOTION_SENSOR_GetAxes(IIS2MDC_0, MOTION_MAGNETO, &mptr->mag ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->mag.x = 0;
- mptr->mag.y = 0;
- mptr->mag.z = 0;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- if ( BSP_ENV_SENSOR_GetValue(LPS22HH_0, ENV_PRESSURE, &mptr->pressure ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->pressure = 0.0f;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- if ( BSP_ENV_SENSOR_GetValue(STTS751_0, ENV_TEMPERATURE, &mptr->temperature ) == BSP_ERROR_COMPONENT_FAILURE )
- {
- mptr->temperature = 0.0f;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- if ( BSP_ENV_SENSOR_GetValue(HTS221_0, ENV_HUMIDITY, &mptr->humidity ) == BSP_ERROR_COMPONENT_FAILURE )//ENV_HUMIDITY &mptr->humidity
- {
- mptr->humidity = 0.0f;
- ret = BSP_ERROR_COMPONENT_FAILURE;
- }
-
- return ret;
- }
2秒更新写一次数据
- DATALOG_SD_Init();
- MX_X_CUBE_MEMS1_Init();
- DATALOG_SD_Log_Enable();
- while(1)
- {
- HAL_Delay(2000);
- getSensorsData(&my_mptr);
- writeSensorsData();
- cnt++;
- if(cnt == 90)
- {
- DATALOG_SD_Log_Disable();
- while(1);
- }
- }
记录完成后生产的数据
下面我们用MATLAB对温度和湿度进行分析。
上电之后对电路板进行加热,可以看到温度快速上升,湿度也跟着下降。
停止加热之后,温度下降和湿度上升然后下降趋于不变的状态。
其他的传感器可以方便的进行分析。
|