cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L UNIQUE ID

Posted on May 26, 2018 at 12:07

Hello to everyone,

I'm designing a simple remote control using STM8L001J3.

To generate a unique 24bit S/N, I would to use the 96bits (12bytes) UNIQUE ID of the micro, readable from 0x4925 address.

There is someone who has already experimented with some method, or algorithm for the calculation?
10 REPLIES 10
Szymon PANECKI
Senior III

Posted on May 26, 2018 at 19:09

Hello Sisto,

This topic was already discussed a bit on this forum. You can refer to these two threads:

  1. https://community.st.com/0D50X00009XkXB0SAN
  2. <LINK NO LONGER ACTIVE>

In second thread Unique Id in

STM8L001J3 is discussed, so in device, which you mentioned.

Regards

Szymon

henry.dick
Senior II
Posted on May 27, 2018 at 18:00

'

using STM8L001J3. To generate a unique 24bit S/N, I would to use the 96bits (12bytes) UNIQUE ID of the micro, readable from 0x4925 address.

 '

the datasheet has all you need for that.

whether your chip has a unique ID, or if it is located at 0x4925, can be checked out in the datasheet too.

Posted on May 27, 2018 at 18:34

The datasheet in this case is less illustrative than other STM8 ones

http://www.st.com/content/ccc/resource/technical/document/datasheet/group3/16/9a/68/4c/7d/03/4a/09/DM00396770/files/DM00396770.pdf/jcr:content/translations/en.DM00396770.pdf

 

This one is better, but still pulling 24-bit unique portion, or hashing is crap shoot.

http://www.st.com/content/ccc/resource/technical/document/datasheet/e1/a6/12/61/ea/f1/4b/b3/CD00200092.pdf/files/CD00200092.pdf/jcr:content/translations/en.CD00200092.pdf

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 28, 2018 at 11:05

Hello to all,

I apologize, but, perhaps, I have not well explained.

The question is not to read UNIQUE ID (see simple asm listing), but use it to calculate a unique 24bit serial number to identifiy the remote control.

In this way I do not need to use rolling code chips or dip switches.

I basically have to use 96-bit UNIQUE ID to get a unique 24-bit number.

...

TINY uint8_t  UNIQUE_ID_BUF[12];

...

// Read STM8L001J3 MCU UNIQUE_ID

#pragma asm

       ldw x,#11

   L1: ld a,($4925,x)

       ld (_UNIQUE_ID_BUF,x),a

       decw x

       jrsge L1

#pragma endasm

Posted on May 28, 2018 at 12:03

Use a hashing function to compute a 24-bits code. It isn't guaranteed to be unique, but is less likely to have collisions than extracting 24 arbitrary bits from the 96 available. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 28, 2018 at 20:08

'

but use it to calculate a unique 24bit serial number to identifiy the remote control.'

1) simply pick 24 bits of data from the uid; or

2) use a hash function on the uid. like crc24.

Posted on June 12, 2018 at 15:09

At last, this is my simple, tested, final solution:

/*

Using the STM8L001J3, 96bit

 UNIQUE_ID, calculate a unique 24 bit serial number for the remote control:

Input : UNIQUE_ID[]

     

= 12 bytes Micro ID Buffer

Output : SERIAL_NUM

     

= Unique 24 bit of remote serial number

       

TELE_FRAME_BUF[] = Compile the first three fields of remote control frame to    transmit

*/

void

CALC_SERIAL_NUM(

void

)

{

   

uint8_t inx;

   

uint32_t Serial_1,Serial_2;

   // Leggi MCU UNIQUE_ID

   

#pragma asm

      

ldw x,#

11

   

L1:

      

ld a,($

4925

,x)

      

ld (_UNIQUE_ID_BUF,x),a

      

decw x

      

jrsge L1

   

#pragma endasm

  //-----------------------

   for

(inx=

0

; inx<

4

; inx++)

   

{

      

Serial_1 += UNIQUE_ID_BUF[inx];

      

Serial_1 <<=

8

;

   

}

   

for

(inx=

4

; inx<

8

; inx++)

   

{

      

Serial_2 += UNIQUE_ID_BUF[inx];

      

Serial_2 <<=

8

;

   

}

   

Serial_1 += Serial_2;

   

for

(inx=

8

; inx<

12

; inx++)

   

{

      

Serial_1 += UNIQUE_ID_BUF[inx];

   

}

//--------------------------------------

   

SERIAL_NUM

 

= Serial_1;

   

Serial_1 >>=

24

;

   

SERIAL_NUM &=

0xFFFFFF

;

   

SERIAL_NUM += Serial_1;

   

TELE_FRAME_BUF[

0

] = (uint8_t) ((SERIAL_NUM &

0xFF0000

) >>

16

);

   

TELE_FRAME_BUF[

1

] = (uint8_t) ((SERIAL_NUM &

0x00FF00

) >>

8

);

   

TELE_FRAME_BUF[

2

] = (uint8_t) (SERIAL_NUM &

0x0000FF

);

}

Posted on June 12, 2018 at 22:04

uint32_t Crc24Quick(uint32_t Crc, size_t Size, uint8_t *Buffer)

{

  static const uint32_t crctab[] = {

    0x00000000,0x01864CFB,0x038AD50D,0x020C99F6,0x0793E6E1,0x0615AA1A,0x041933EC,0x059F7F17,

    0x0FA18139,0x0E27CDC2,0x0C2B5434,0x0DAD18CF,0x083267D8,0x09B42B23,0x0BB8B2D5,0x0A3EFE2E };

  while(Size--)

  {

    Crc ^= (uint32_t)*Buffer++ << 16;

    Crc = (Crc << 4) ^ crctab[(Crc >> 20) & 0x0F];

    Crc = (Crc << 4) ^ crctab[(Crc >> 20) & 0x0F];

  }

  return(Crc & 0xFFFFFF);

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 13, 2018 at 01:02

'

At last, this is my simple, tested, final solution:'

no fun if we cannot re-invent the wheels,