This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Hello, I'm working over the LAUNCHXL-CC2640R2, using the SHT31 sensor.
This the code:
These the output errors:
my experience on C/C++ is few, so these errors may be easy to correct but I'm just wondering around, any help is deeply appreciated
Working with CCSv 7.4, and Compiler 16.9.6
Thanks!
I'll comment on two of the lines. I suspect fixing these will cause most of the remaining problems to go away.
Regarding ...
const uint8_t POLYNOMIAL(0x31);
Initializing a local variable like that is not valid in C. But it is valid in C++. To make it work in C, write it ...
const uint8_t POLYNOMIAL = 0x31;
Or, if you have a lot of this thing already, consider changing the file extension for the source file from .c to .cpp. This is the typical way to tell the compiler the source is C++, and not C.
Regarding ...
uint8_t *crc(0xFF);
As for the initialization to 0xFF, it has the same problem as the previous example. But there is an additional problem. Note the * character. This says this is a pointer variable. Given the context, you don't want this variable to be a pointer, but a value. Remove the *.
Thanks and regards,
-George
Thank you very much for your answer.
Code with the proposed fixes and I corrected others as well... final code looks like this:
uint8_t crc8(const uint8_t *data, int len) { const uint8_t POLYNOMIAL = 0x31; uint8_t crc = 0xFF; unsigned int j = 0; unsigned int i = 0; for (j = len; j; --j ) { crc ^= *data++; for (i = 8; i; --i ) { crc = ( crc & 0x80 ) ? (crc << 1) ^ POLYNOMIAL : (crc << 1); } } return crc; }
(Post it in the case would be useful for someone else...)
I solved the previous Issue, will post a new question for the other errors. thanks