2018-05-26 03:07 AM
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?2018-05-26 10:09 AM
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:
In second thread Unique Id in
STM8L001J3 is discussed, so in device, which you mentioned.
Regards
Szymon
2018-05-27 09:00 AM
'
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.
2018-05-27 11:34 AM
The datasheet in this case is less illustrative than other STM8 ones
This one is better, but still pulling 24-bit unique portion, or hashing is crap shoot.
2018-05-28 02:05 AM
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
2018-05-28 05:03 AM
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.
2018-05-28 01:08 PM
'
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.
2018-06-12 06:09 AM
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
);}
2018-06-12 03:04 PM
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);
}2018-06-12 06:02 PM
'
At last, this is my simple, tested, final solution:'
no fun if we cannot re-invent the wheels,