cancel
Showing results for 
Search instead for 
Did you mean: 

Generating random number

DDavy.1
Associate

We have many STM8S001J3 connected to the same data bus. Each of them should generate a random number to use it as its own ID. We cannot use ADC to generate the number because all pins are in use. We cannot use clock because all MSU boot at the same time. Any other variants?

3 REPLIES 3
Cristian Gyorgy
Senior III

You could try to start the watchdog timer and let it reset the mcu, and while waiting for the reset disable interrupts and continuously increment a SRAM location. After reset, you can check the reset flags, and if it was watchdog reset than read the SRAM location. Without power off it should have the last value.

Now let's say you increment the SRAM location with 1MHz (1µs) and the watchdog timeout could be somewhere 50..100 ms, the differences in LSI RC oscillator should generate quite random numbers due to the different timeout period.

Of course you would need another mechanism to guarantee you it was an intended reset, but that should be easy - you have 2 watchdog timers.

Datasheet says that ADC has internal bandgap reference on AIN7. What about measure that... ?

Another source of randomness can be frequencies od HSI and LSI clocks (what about to measure their ratio ?). Another random probably can be obtained from EEPROM write or erase times ...