change to transmit/receive IT mode

This commit is contained in:
Yunhorn 2025-02-05 17:20:18 +08:00
parent 9a0b055952
commit 3bc660cbb1
3 changed files with 18 additions and 7 deletions

View File

@ -104,6 +104,8 @@ int main(void)
MX_USART1_UART_Init();
/* USER CODE END 2 */
sts_sensor_o3_t o3_data;
@ -116,6 +118,8 @@ int main(void)
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);
HAL_Delay(4000);
HAL_Delay(4000);
HAL_Delay(4000);
} while (i++ <20);
}

View File

@ -39,7 +39,7 @@ void sts_aq_o3_init(void)
int sts_aq_o3_start_autony_mode(void)
{
printf("change to autony mode\r\n");
if (HAL_UART_Transmit(&huart1, (uint8_t *)autonymode, 9, 5000) != HAL_OK)
if (HAL_UART_Transmit_IT(&huart1, (uint8_t *)autonymode, 9) != HAL_OK)
{
printf("\r\n Transmit anony mode failure \r\n");
return -1;
@ -50,7 +50,7 @@ int sts_aq_o3_start_autony_mode(void)
int sts_aq_o3_start_pooling_mode(void)
{
printf("change to querymode\r\n");
if (HAL_UART_Transmit(&huart1, (uint8_t *)querymode, 9, 5000) != HAL_OK)
if (HAL_UART_Transmit_IT(&huart1, (uint8_t *)querymode, 9) != HAL_OK)
{
printf("\r\n Transmit pooling mode failure \r\n");
return -1;
@ -61,7 +61,7 @@ int sts_aq_o3_start_pooling_mode(void)
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(&huart1, (uint8_t *)aRxBuffer, 9, 0x5000) != HAL_OK)
if (HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 9) != HAL_OK)
{
printf("\r\n Transmit receiving data failure \r\n");
}
@ -81,19 +81,26 @@ void sts_aq_o3_autony_run_mode(sts_sensor_o3_t *sts_sensor_data)
int sts_aq_o3_query(sts_sensor_o3_t *sts_sensor_data)
{
if (HAL_UART_Transmit(&huart1, (uint8_t *)queryonce, 9, 5000) != HAL_OK)
uint8_t i=0;
if (HAL_UART_Transmit_IT(&huart1, (uint8_t *)queryonce, 9) != HAL_OK)
{
printf("\r\n Transmit query once failure \r\n");
return -1;
} else {
printf("\r\n Query cmd sent out = ");
for (i=0; i< sizeof(queryonce); i++)
printf("%02x ",*(queryonce+i));
}
if (HAL_UART_Receive(&huart1, (uint8_t *)aRxBuffer, 9, 0x5000) != HAL_OK)
if (HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 9) != HAL_OK)
{
printf("\r\n Transmit receiving data failure \r\n");
printf("\r\n UART Receiving data failure \r\n");
return -2;
} else {
printf("\r\n UART Receiving data \r\n");
}
printf("\n Sensor data = ");
printf("\n Received data = ");
for (uint8_t j=0; j<sizeof(aRxBuffer); j++)
printf(" %02x ",aRxBuffer[j]);