Skip to content

Instantly share code, notes, and snippets.

@PaulStoffregen
Created December 3, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulStoffregen/965c0676ee34bd55b2f6c23e992a0ed3 to your computer and use it in GitHub Desktop.
Save PaulStoffregen/965c0676ee34bd55b2f6c23e992a0ed3 to your computer and use it in GitHub Desktop.
Quick Entropy library raw data test
// A very quick entropy test. Run on Teensy 3.x or Teensy LC.
// https://twitter.com/DavidInOregon/status/937304504210423808
volatile uint8_t val=0;
volatile bool newval=false;
void setup() {
SIM_SCGC5 |= SIM_SCGC5_LPTIMER;
LPTMR0_CSR = 0b10000100;
LPTMR0_PSR = 0b00000101; // PCS=01 : 1 kHz clock
LPTMR0_CMR = 0x0006; // smaller number = faster random numbers...
LPTMR0_CSR = 0b01000101;
NVIC_ENABLE_IRQ(IRQ_LPTMR);
}
void lptmr_isr(void)
{
LPTMR0_CSR = 0b10000100;
LPTMR0_CSR = 0b01000101;
val = SYST_CVR;
newval = true;
}
void loop() {
if (newval) {
newval = false;
Serial.println(val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment