STM32F407VE How to use RNG?

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

STM32F407VE How to use RNG?

#1 Post by Vit2 » 29 Nov 2021 20:39

Hey!
What am I doing wrong?

Code: Select all

 procedure InitRNG();
 begin
 RNGEN_RCC_AHB2ENR_bit:= 1;
 RCC_AHB2ENR:= 1;
 RNGEN_bit:= 1;
 end;
 
 function ColorRNG( color:dWORD;):dWORD;
 var
 Rnd:DWORD;
 begin
  RNG_CR:=1;
  while (RNG_SR = 1)do
  begin
  RNG_DR:=1;
  Rnd := RNG_DR;
  end;
  result:= Rnd;
 end;
 
 
 TFT9341_WriteStringN(5,70,'Test Color',ColorRNG(TFT9341_YELLOW),TFT9341_BLUE,CourierNew15x29Bold,15,29);
 

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F407VE How to use RNG?

#2 Post by Vit2 » 02 Dec 2021 14:09

RNG works in Pascal?
Or not anyone knows?

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: STM32F407VE How to use RNG?

#3 Post by Thomas.Pahl@t-online.de » 02 Dec 2021 16:37

This is working example from a former project:

[code]
sub function init_rng as word ' reinit Random-Number-Generator
seis_bit = 0 ceis_bit = 0
RCC_AHB2ENR.6 = 0 ' clock ausschalten
RNG_CR.2 = 0 ' RNG ausschalten
nop nop nop nop nop
RCC_AHB2ENR.6 = 1 ' clock einschalten
RNG_CR.2 = 1 ' RNG einschalten
while secs_bit = 1 wend
if (seis_bit = 0) and (ceis_bit = 0) then result = 0 else result = 1 end if ' Erfolg?
end sub


sub function get_rnd as longword
if seis_bit then
seis_bit = 0 ' restart
RNG_CR.2 = 0
nop nop
RNG_CR.2 = 1
while secs_bit = 1
wend
end if
if ceis_bit then
ceis_bit = 0
while secs_bit = 1
wend
end if
while RNG_SR.0 = 0 wend 'wait for data ready
result = rng_dr
end sub
[/code]

You see the beauty of basic language? :D

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F407VE How to use RNG?

#4 Post by Vit2 » 02 Dec 2021 18:16

Thank you!
I will sort this out

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F407VE How to use RNG?

#5 Post by Vit2 » 03 Dec 2021 07:44

Thank you Thomas.
My code also works, I forgot to make a delay.

Post Reply

Return to “mikroPascal PRO for ARM General”