【发布时间】: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