Hi Thomas,
I'm not entirely sure what the above code is supposed to be doing, but
converting a real number to hex is not that difficult. The idea is to
shift out the highest nibble (4 bits) first, because that needs to be
outputted first, and then the 2nd higest, etc...
void uint64ToHexString(uint64_t inp, uint8_t * outbuf)
{
int v;
int shift;
// count down, so highest nibble comes first
for (shift = 60; shift >= 0; shift -= 4) {
// shift out 4 bits and mask, thus keeping only 4 bits
v = (inp >> shift) & 0xF;
// v is now the value between 0 and 15.
// if its below 10, we simply take '0' and add v, cause '0' + 1 =
'1'
if (v < 10) {
*outbuf = '0' + v;
} else {
// otherwise, we take 'a', add v - 10, cause 'a' + (11 - 10) = 'b'
*outbuf = 'a' + (v - 10);
}
// increase output pointer to next character
outbuf++;
}
// null terminate, so it plays nice with printf() and such
*outbuf = '\0';
}
Now you can define an temporary buffer, needs to be one byte bigger than
the number of hex characters, e.g. for 64 bit value, this would be 8 * 2
+ 1.
uint64_t hexValue = CS_UID;
uint8_t output[17];
uint64ToHexString(hexValue, output);
appWriteDataToUart(output, 16);
Regards,
Vincent