【问题标题】:use RNG library in stm32f4xx在 stm32f4xx 中使用 RNG 库
【发布时间】:2019-02-01 15:38:58
【问题描述】:

我想用stm32f4xx发现板的内置硬件编写简单的代码来生成随机数。我写了下面的代码,但它不起作用。它停留在内部 while 循环中,并且标志永远不会设置为跳出循环。

#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();
    }
}

【问题讨论】:

    标签: random stm32 stm32f4discovery stm32f4


    【解决方案1】:

    我自己通过在 main 函数的开头添加 SystemInit() 解决了这个问题。

    【讨论】:

      【解决方案2】:

      只需在以下网址学习 STMicroelectronics 示例 STM32CubeH7-master\Projects\NUCLEO-H743ZI\Examples\RNG\RNG_MultiRNG

      代码可以从github下载。谷歌搜索STM32CubeH7-master和github

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-19
        • 2019-11-23
        • 1970-01-01
        • 2014-11-05
        • 2013-02-27
        • 1970-01-01
        • 2020-11-28
        相关资源
        最近更新 更多