2626/* Private includes ----------------------------------------------------------*/
2727/* USER CODE BEGIN Includes */
2828#include "AHT20.h"
29+ #include "utils.h"
2930#include <stdio.h>
3031#include <string.h>
3132/* USER CODE END Includes */
@@ -69,31 +70,6 @@ void UART_Send_String(const char* str)
6970 HAL_UART_Transmit (& huart2 , (uint8_t * )str , strlen (str ), HAL_MAX_DELAY );
7071}
7172
72- /* prints error message to UART based on received status */
73- void print_error (aht20_status_t status ) {
74- char debug_msg [64 ] = "\0" ;
75-
76- if (status == AHT20_STATUS_NOT_TRANSMITTED ) {
77- sprintf (debug_msg , "I2C initialization transmit error: 0x71\r\n" );
78- UART_Send_String (debug_msg );
79- } else if (status == AHT20_STATUS_NOT_RECEIVED ) {
80- sprintf (debug_msg , "I2C initialization recieve error: status_word\r\n" );
81- UART_Send_String (debug_msg );
82- } else if (status == AHT20_STATUS_NOT_CALIBRATED ) {
83- sprintf (debug_msg , "I2C device calibration error\r\n" );
84- UART_Send_String (debug_msg );
85- } else if (status == AHT20_STATUS_NOT_MEASURED ) {
86- sprintf (debug_msg , "I2C device couldn't perform measuring\r\n" );
87- UART_Send_String (debug_msg );
88- } else if (status == AHT20_STATUS_OK ) {
89- /* doing nothing if ok */
90- }
91- else {
92- sprintf (debug_msg , "Unknown error\r\n" );
93- UART_Send_String (debug_msg );
94- }
95- }
96-
9773/* transmits data to UART */
9874void transmit_data (float humidity , float temperature_c , float temperature_f ) {
9975 char data_to_display [60 ] = "\0" ;
@@ -144,9 +120,9 @@ int main(void)
144120 aht20_status_t status = AHT20_STATUS_OK ;
145121
146122 /* getting info about sensor calibration */
147- status = aht20_get_calibration_status (& hi2c1 , & huart2 , & status_word , (uint16_t )sizeof (status_word ));
123+ status = aht20_get_calibration_status (& hi2c1 , & status_word , (uint16_t )sizeof (status_word ));
148124 if (status != AHT20_STATUS_OK ) {
149- print_error (status );
125+ print_error (& huart2 , status );
150126 return 1 ;
151127 } else {
152128 /* checks if calibration is valid */
@@ -155,7 +131,7 @@ int main(void)
155131 /* calibrates if not calibrated*/
156132 status = aht20_calibrate (& hi2c1 , status_word );
157133 if (status != AHT20_STATUS_OK ) {
158- print_error (status );
134+ print_error (& huart2 , status );
159135 return 2 ;
160136 }
161137 }
@@ -172,7 +148,7 @@ int main(void)
172148 /* triggering measuring */
173149 status = aht20_measure (& hi2c1 , sensor_data .measured_data , (uint16_t )sizeof (sensor_data .measured_data ));
174150 if (status != AHT20_STATUS_OK ) {
175- print_error (status );
151+ print_error (& huart2 , status );
176152 aht20_soft_reset (& hi2c1 );
177153 continue ;
178154 }
0 commit comments