Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Antoniomilano opened this issue May 30, 2020 · 1 comment
Open

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

Antoniomilano opened this issue May 30, 2020 · 1 comment

Comments

@Antoniomilano
Copy link

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

@eepj
Copy link
Owner

eepj commented May 31, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants