Small program to read the Part ID and Device Serial Number using IAP commands.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * How to read LPC1768 part ID and device serial number
00003  * Dan Minear
00004  * 2012-11-08
00005  */
00006  
00007 #include "mbed.h"
00008 
00009 #define IAP_LOCATION 0x1FFF1FF1
00010 
00011 typedef void (*IAP)(unsigned long [], unsigned long[] );
00012 IAP iap_entry = (IAP) IAP_LOCATION;
00013 
00014 DigitalOut myled(LED1);
00015 
00016 int main() {
00017     unsigned long command[5] = {0,0,0,0,0};
00018     unsigned long result[5] = {0,0,0,0,0};
00019 
00020     printf("\r\nStart...\r\n");
00021     
00022     // See User Manual section 32.8.5
00023     command[0] = 54;    // partID
00024     printf("\r\nPart ID: (should be 0x2601 3F37 for LPC1768)\r\n");
00025     iap_entry(command, result);
00026     if (result[0] == 0) {
00027         for(int i = 1; i < 2; i++) {
00028             printf( "0x%x\r\n", result[i] );
00029         }
00030     } else {
00031         printf("Status error!\r\n");
00032     }
00033     
00034     // See User Manual section 32.8.7
00035     command[0] = 58;  // read device serial number
00036     printf("\r\nSerial number:\r\n");
00037     iap_entry(command, result);
00038     if (result[0] == 0) {
00039         for(int i = 1; i < 5; i++) {
00040             printf( "0x%x\r\n", result[i] );
00041         }
00042     } else {
00043         printf("Status error!\r\n");
00044     }
00045         
00046     printf( "\r\nEnd\r\n" );
00047         
00048     // and now back to the default new project, just flash a LED
00049     while(1) {
00050         myled = 1;
00051         wait(0.2);
00052         myled = 0;
00053         wait(0.2);
00054     }
00055 }