dimanche 26 août 2018

use RNG library in stm32f4xx

I want to write simple code to generate random number with built-in hardware in stm32f4xx discovery board. I wrote the code below but it does not work. It sticks in inner while loop and the flag never set to jump out of loop.

#include <stm32f4xx.h>
#include <stm32f4xx_rng.h>
#include <stm32f4xx_rcc.h>

void RNG_Config(void)
{
    /* Enable RNG clock source */
    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);

    /* RNG Peripheral enable */
    RNG_Cmd(ENABLE);
}

int main(void)
{

    uint32_t temp = 0;
    RNG_Config();

    while(1)
    {
        while (RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);

        temp = RNG_GetRandomNumber();
    }
}




Aucun commentaire:

Enregistrer un commentaire