代码下载地址:
https://download.csdn.net/download/qq_31806069/12569995
int main(void)
{
char buf[30];
simple_uart_config(0xff,9,0xff,11,false);
uart_exit();
while(1)
{
sprintf(buf,"rng:%02x\r\n",get_rng());
simple_uart_putstring((const uint8_t *)buf);
nrf_delay_ms(1000);
}
}
uint8_t get_rng(void)
{
uint8_t result = 0;
NRF_RNG->TASKS_START = 1; // start the RNG peripheral.
// Clear the VALRDY EVENT.
NRF_RNG->EVENTS_VALRDY = 0;
// Wait until the value ready event is generated.
while (NRF_RNG->EVENTS_VALRDY == 0)
{
// Do nothing.
}
result = (uint8_t)NRF_RNG->VALUE;
NRF_RNG->TASKS_STOP = 1;
return result;
}
效果:
rng:c1
rng:da
rng:51
rng:68
rng:86
rng:ef
rng:db
rng:cc
rng:be
rng:f1
rng:70
rng:93
rng:a1
rng:d0
rng:ef
rng:af
rng:a3
rng:ef
rng:98
rng:68
rng:a5
rng:ec
rng:19
rng:42
rng:5f
rng:1d
网友评论