lgt8fx icon indicating copy to clipboard operation
lgt8fx copied to clipboard

How to build the serial number?

Open RudolfAtHome opened this issue 3 years ago • 4 comments

The file "lgt8xp.h" contains 4 pointers for reading out the serial number. In which order do the values have to be linked with one another? #define GUID0 (*((volatile unsigned char )0xF3)) #define GUID1 (((volatile unsigned char )0xF4)) #define GUID2 (((volatile unsigned char )0xF5)) #define GUID3 (((volatile unsigned char *)0xF6))

RudolfAtHome avatar May 14 '21 18:05 RudolfAtHome

I think no rule how to use it.

uint32_t guid = (uint32_t)&GUID0;
Serial.println(guid, HEX);
uint32_t guid = ((uint32_t)GUID3 << 24) | (GUID2 << 16) | (GUID1 << 8) | GUID0;
Serial.println(guid, HEX);
#define guid (*((volatile uint32_t *)0xF3))
Serial.println(guid, HEX);

LaZsolt avatar May 14 '21 20:05 LaZsolt

To Lazolt: This gives very strange / incorrect results, so my question remains open!

uint32_t guid = (uint32_t)&GUID0; Serial.println(guid, HEX); Result: F3 -> wrong, that's an address? uint32_t guid = ((uint32_t)GUID3 << 24) | (GUID2 << 16) | (GUID1 << 8) | GUID0; Serial.println(guid, HEX); Result: FFFFAB8A -> looks not very serious #define guid (*((volatile uint32_t *)0xF3)) Serial.println(guid, HEX); Result: 6F49AB8A -> another result...

RudolfAtHome avatar May 15 '21 09:05 RudolfAtHome

I tested it. I think we run into a compiler bug. If GUID1 bigger than 0x7F then the (unit32_t) shift result upper two bytes will be 0xFFFF. With another words. If an unsigned 8 bit variable which bigger than 0x7F and shifted left by 8, then the result negative 16 bit number. (integer)

LaZsolt avatar May 15 '21 12:05 LaZsolt

Here is the tested GUID printing sketch.

/* GUID test */

uint32_t guid_a, guid_b, guid_c, guid_d;

void setup() {
  Serial.begin(38400);

  guid_a = (*((uint32_t *)&GUID0));
  Serial.println(guid_a, HEX);


  Serial.println((*((uint32_t *)&GUID0)), HEX);


#define guid_b (*((uint32_t *)0xF3))
  Serial.println(guid_b, HEX);


  Serial.println((*((uint32_t *)0xF3)), HEX);


  guid_c = ((uint32_t)GUID3 << 24) | ((uint32_t)GUID2 << 16) | ((uint32_t)GUID1 << 8) | GUID0;
  Serial.println(guid_c, HEX);

  Serial.println();
  Serial.println();
}

void loop() {}

LaZsolt avatar May 15 '21 12:05 LaZsolt

@RudolfAtHome does this code work for you? If so, please close this issue.

dwillmore avatar Jan 12 '23 19:01 dwillmore

It's solved for me since May 15, 2021

RudolfAtHome avatar Jan 12 '23 20:01 RudolfAtHome