diff --git a/Core/Src/main.c b/Core/Src/main.c index 313cc53..11de389 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -115,8 +115,10 @@ int main(void) if (sts_aq_o3_start_pooling_mode() ==0) { do { - sts_aq_o3_query(&o3_data); - printf("\r\n cycle %d: o3 =%4d %s : %.2f mg/m3 \r\n", i, o3_data.o3_ppb, (o3_data.o3_unit==0x04)?"ppb":"non", o3_data.o3_mg_per_m3); + if (sts_aq_o3_query(&o3_data) ==0) + { + printf("\r\n cycle %d: o3 =%4d %s : %.2f mg/m3 \r\n", i, o3_data.o3_ppb, (o3_data.o3_unit==0x04)?"ppb":"non", o3_data.o3_mg_per_m3); + } HAL_Delay(4000); HAL_Delay(4000); HAL_Delay(4000); diff --git a/Core/Src/sts_aq_o3.c b/Core/Src/sts_aq_o3.c index c27fe52..6964cf2 100644 --- a/Core/Src/sts_aq_o3.c +++ b/Core/Src/sts_aq_o3.c @@ -43,6 +43,8 @@ int sts_aq_o3_start_autony_mode(void) { printf("\r\n Transmit anony mode failure \r\n"); return -1; + } else { + printf("\r\n Change to anony mode success \r\n"); } return 0; } @@ -63,7 +65,8 @@ void sts_aq_o3_autony_run_mode(sts_sensor_o3_t *sts_sensor_data) /*##-1- Put UART peripheral in reception process ###########################*/ if (HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 9) != HAL_OK) { - printf("\r\n Transmit receiving data failure \r\n"); + printf("\r\n Periodic Receiving data failure ...........\r\n"); + return ; } printf("\nSensor data = "); @@ -96,19 +99,20 @@ int sts_aq_o3_query(sts_sensor_o3_t *sts_sensor_data) { printf("\r\n UART Receiving data failure \r\n"); return -2; - } else { - printf("\r\n UART Receiving data \r\n"); } - printf("\n Received data = "); for (uint8_t j=0; j<sizeof(aRxBuffer); j++) printf(" %02x ",aRxBuffer[j]); - - sts_sensor_data->o3_ppb = (int)(aRxBuffer[4]*256+aRxBuffer[5]); - sts_sensor_data->o3_range = (int)(aRxBuffer[6]*256+aRxBuffer[7]); - sts_sensor_data->o3_unit = (uint8_t)aRxBuffer[2]; - sts_sensor_data->o3_mg_per_m3 = (float)(2.140*(float)((aRxBuffer[4]*256+aRxBuffer[5])/1000.0)); - + if ((aRxBuffer[0] ==0xff)&&(aRxBuffer[1] == 0x17)) + { + sts_sensor_data->o3_ppb = (int)(aRxBuffer[4]*256+aRxBuffer[5]); + sts_sensor_data->o3_range = (int)(aRxBuffer[6]*256+aRxBuffer[7]); + sts_sensor_data->o3_unit = (uint8_t)aRxBuffer[2]; + sts_sensor_data->o3_mg_per_m3 = (float)(2.140*(float)((aRxBuffer[4]*256+aRxBuffer[5])/1000.0)); + } else { + printf("\r\n Received data invalid xxxxx \r\n"); + return -3; + } return 0; // printf("\r\n Seq:=%5d Read O3 = %d (ppb) [Range=%d unit=%s ] | == %.2f mg/m3 \r\n", i, (int)(aRxBuffer[4]*256+aRxBuffer[5]), // (int)(aRxBuffer[6]*256+aRxBuffer[7]),(aRxBuffer[2]==0x04)?"ppb":"ppm", (float)(2.140*(float)((aRxBuffer[4]*256+aRxBuffer[5])/1000.0))); diff --git a/STM32CubeIDE/Release/WL55JC_AS923.elf b/STM32CubeIDE/Release/WL55JC_AS923.elf index c7360a9..be067b6 100644 Binary files a/STM32CubeIDE/Release/WL55JC_AS923.elf and b/STM32CubeIDE/Release/WL55JC_AS923.elf differ