stm32-sht2x icon indicating copy to clipboard operation
stm32-sht2x copied to clipboard

Issue with the sprintf(buffer) using the example.c

Open Antoniomilano opened this issue 5 years ago • 1 comments
trafficstars

Hello, first of all, thank you very much for your code, it works very fine, but... trying your example.c, things goes very good if I comment out this function and read the values of cel, fah, kel, rh, using the Atollic TrueStudio debugger window. If I uncomment the function, to prepare the messages to put on a terminal: sprintf(buffer, "%d.%dºC, %d.%dºF, %d.%d K, %d.%d%% RH\n", SHT2x_Pre(cel), SHT2x_Post(cel, 1), SHT2x_Pre(fah), SHT2x_Post(fah, 1), SHT2x_Pre(kel), SHT2x_Post(kel, 1), SHT2x_Pre(rh), SHT2x_Post(rh, 1)); The following errors are found: undefined reference to "SHT2x_Post" undefined reference to "SHT2x_Pre" Where are these functions and what they do? Thank you very much Antoniomilano

Antoniomilano avatar May 30 '20 19:05 Antoniomilano

Hello. Sorry about the error. This is because I renamed these functions in the .c and .h files but forgot to update main.c. I have updated main.c just now.

The function int32_t SHT2x_GetInteger(float f) (previously defined asSHT2x_Pre(float f)) returns the integer part of a floating point value f.

The function uint32_t SHT2x_GetDecimal(float f, int digits) (previously defined asSHT2x_Post(float f, int digits)) returns the decimal part of a floating point value f, with precision up to digits.

For example, SHT2x_GetInteger(1.234) returns 1 and SHT2x_GetDecimal(1.234, 2) returns 23. Calling sprintf(buffer, "%d.%d", SHT2x_GetInteger(1.234), SHT2x_GetDecimal(1.234, 2)); formats the string buffer as "1.23".

If you can work with floating point values, you can directly use the values cel, rh, etc. The reason I came up with these two functions is that I wanted to avoid floating point value formatting with sprintf, which takes up a lot of memory in the microcontroller.

Please update main.c and see if it compiles? Sorry again about the inconvenience.

eepj avatar May 31 '20 18:05 eepj