Created
January 29, 2016 15:25
-
-
Save mgk/c9ec87436d2d679e5d08 to your computer and use it in GitHub Desktop.
Arduino SAMD / Arduino Zero / Arduino M0 chip unique serial number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Print SAMD chip serial number. | |
* | |
* http://atmel.force.com/support/articles/en_US/FAQ/Reading-unique-serial-number-on-SAM-D20-SAM-D21-SAM-R21-devices | |
*/ | |
void setup() { | |
Serial.begin(9600); | |
delay(1000); | |
} | |
void loop() { | |
printChipId(); | |
delay(3000); | |
} | |
void printChipId() { | |
volatile uint32_t val1, val2, val3, val4; | |
volatile uint32_t *ptr1 = (volatile uint32_t *)0x0080A00C; | |
val1 = *ptr1; | |
volatile uint32_t *ptr = (volatile uint32_t *)0x0080A040; | |
val2 = *ptr; | |
ptr++; | |
val3 = *ptr; | |
ptr++; | |
val4 = *ptr; | |
Serial.print("chip id: 0x"); | |
char buf[33]; | |
sprintf(buf, "%8x%8x%8x%8x", val1, val2, val3, val4); | |
Serial.println(buf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey thanks! Worked for me on Adafruit FeatherM0's. Before this I had been using extra analog pins to hardwire unique ID's for feathers with RFM69 packet radios.